我正在使用django的登录视图,但在设置网址后,我收到了错误。我在互联网上搜索但无法解决此问题。
from django.conf.urls import include, url
from django.contrib import admin
urlpatterns = [
url(r'^admin/', include(admin.site.urls)),
url(r'^users/', include('users.urls', namespace='users')),
url(r'', include('learning_logs.urls', namespace='learning_logs')),
]
from django.conf.urls import url
from django.contrib.auth import views as auth_views
from . import views
urlpatterns = [
url(r'^login/$', auth_views.login, {'template_name': 'users/login.html'}, name='login'),
]
from django.conf.urls import url
from . import views
urlpatterns = [
# Home Page
url(r'^$',views.index,name='index'),
# Show all topics
url(r'^topics/$', views.topics, name='topics'),
# Show topic detail, r tells django to interpret the string as raw string
url(r'^topics/(?P<topic_id>\d+)/$', views.topic, name='topic'),
url(r'^new_topic/$', views.new_topic, name='new_topic'),
url(r'^new_entry/(?P<topic_id>\d+)/$',views.new_entry, name='new_entry'),
url(r'^edit_entry/(?P<entry_id>\d+)/$', views.edit_entry, name='edit_entry'),
]
Environment:
Request Method: GET
Request URL: http://localhost:8000/users/login
Django Version: 1.8
Python Version: 3.4.2
Installed Applications:
('django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'learning_logs',
'users')
Installed Middleware:
('django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
'django.middleware.security.SecurityMiddleware')
Traceback:
File "C:\Python34\lib\site-packages\django\core\handlers\base.py" in get_response
108. response = middleware_method(request)
File "C:\Python34\lib\site-packages\django\middleware\common.py" in process_request
74. if (not urlresolvers.is_valid_path(request.path_info, urlconf) and
File "C:\Python34\lib\site-packages\django\core\urlresolvers.py" in is_valid_path
647. resolve(path, urlconf)
File "C:\Python34\lib\site-packages\django\core\urlresolvers.py" in resolve
522. return get_resolver(urlconf).resolve(path)
File "C:\Python34\lib\site-packages\django\core\urlresolvers.py" in resolve
368. sub_match = pattern.resolve(new_path)
File "C:\Python34\lib\site-packages\django\core\urlresolvers.py" in resolve
368. sub_match = pattern.resolve(new_path)
Exception Type: AttributeError at /users/login
Exception Value: 'str' object has no attribute 'resolve'
from django.conf.urls import include, url
from django.contrib import admin
from django.contrib.auth.views import login
extra_patterns = [
url(r'^login/$', login, {'template_name' : 'users/login.html'}, name='login'),
]
urlpatterns = [
url(r'^admin/', include(admin.site.urls)),
url(r'^users/', include(extra_patterns, namespace='users')),
url(r'', include('learning_logs.urls', namespace='learning_logs')),
]