Justin Boucher
Justin Boucher

Reputation: 301

Django URL endswith

It's been awhile since I worked in Django and I'm pretty rusty. I'm trying to create a new project and app, and I copy and pasted some code from a previous (and working) app, so I didn't have to type everything from scratch, but I keep getting the following error when trying to run the server:

File "/home/jboucher/anaconda3/envs/test_pilot/lib/python3.6/site-packages/django/core/checks/urls.py", line 104, in check_url_settings if value and not value.endswith('/'):

AttributeError: 'tuple' object has no attribute 'endswith'

I know i'm just missing something simple but I can't seem to find it. Here is my code, with a lot of unused code commented out for now:

project urls:

from django.conf.urls import url, include
from django.contrib import admin
from django.conf import settings
from django.conf.urls.static import static

urlpatterns = [
    url(r'', include('test_pilot.urls', namespace='test_pilot')),
    url(r'^admin/', admin.site.urls),
] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)

App urls:

from django.conf.urls import url

from . import views

app_name = 'test_pilot'

urlpatterns = [
    url(r'^$', views.IndexView.as_view(), name='index'),
#    url(r'^accounts/login/$', views.LoginView.as_view(), name='login'),
#    url(r'^logout/$', views.LogoutView.as_view(), {'next_page': '/accounts/login'}, name='logout'),
]

app views.py

from django.contrib.auth import REDIRECT_FIELD_NAME, logout as auth_logout
from django.contrib.auth.views import LoginView as AuthLoginView
from django.utils.http import is_safe_url
from django.views.generic import TemplateView, RedirectView
from django.utils.decorators import method_decorator
from django.contrib.auth.decorators import login_required


#@method_decorator(login_required, name='test_pilot')
class IndexView(TemplateView):
    template_name = 'pages/index.html'

    def test_pilot(self, *args, **kwargs):
        return super(IndexView, self).dispatch(*args, **kwargs)


# class LoginView(AuthLoginView):
#     success_url = '/'
#     template_name = 'pages/login.html'
#     redirect_field_name = REDIRECT_FIELD_NAME
#
#     def get_success_url(self):
#         redirect_to = self.request.GET.get(self.redirect_field_name)
#         if not is_safe_url(url=redirect_to, host=self.request.get_host()):
#             redirect_to = self.success_url
#         return redirect_to
#
#
# class LogoutView(RedirectView):
#     """
#     Provides users the ability to logout
#     """
#     url = '/accounts/login/'
#
#     def get(self, request, *args, **kwargs):
#         auth_logout(request)
#         return super(LogoutView, self).get(request, *args, **kwargs)

And my template is just a simple hello world html page for right now. Again, I know i'm missing something simple, but its been a really long time since I touched any Django programming.

Upvotes: 0

Views: 869

Answers (1)

Daniel Roseman
Daniel Roseman

Reputation: 599926

The problem is in your settings file: one of STATIC_URL or MEDIA_URL has a trailing comma, which turns it into a tuple.

Upvotes: 2

Related Questions