自从我在Django工作以来已经有一段时间了,而且我很生气。我正在尝试创建一个新的项目和应用程序,我复制并粘贴了以前(和工作)应用程序中的一些代码,所以我不必从头开始键入所有内容,但我在尝试时遇到以下错误运行服务器:
文件“/home/jboucher/anaconda3/envs/test_pilot/lib/python3.6/site-packages/django/core/checks/urls.py”,第104行,在check_url_settings中 if value而不是value.endswith('/'):
AttributeError:'tuple'对象没有属性'endswith'
我知道我只是错过了一些简单的东西,但我似乎无法找到它。这是我的代码,目前已注释掉许多未使用的代码:
项目网址:
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)
应用网址:
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)
我的模板现在只是一个简单的hello world html页面。再一次,我知道我错过了一些简单的东西,但是自从我触及任何Django编程以来,它已经很长时间了。
答案 0 :(得分:1)
问题出在您的设置文件中:STATIC_URL
或MEDIA_URL
中的一个有一个逗号,它会将其转换为元组。