当我尝试使用ImportError "No module named django.contrib.auth"
django.shortcuts
函数并尝试使用时,我得到了redirect
:
(r'^logout/$', 'django.contrib.auth.views.logout', {'next_page': '/'}),
我认为,我遇到此错误的唯一地方是在重定向页面的地方,但可能确实如此。我知道用户实际上并未注销,因此在您获得任何重定向代码之前就会发生错误。
以下是我的urls.py文件。
import django.contrib.auth.views
from django.conf.urls.defaults import *
import django.contrib.auth
from django.contrib import admin
admin.autodiscover()
urlpatterns = patterns('karma.views',
(r'^$', 'homepage'),
(r'^logout/$', 'django.contrib.auth.views.logout', {'next_page': '/'}),
(r"^opportunities/nearby$", 'draw_map'),
(r'^admin/', include(admin.site.urls)),
url(r'', include('social_auth.urls')),
(r'^profile/', include('karmup.profile.urls')),
)
答案 0 :(得分:28)
您正在混合urlpatterns
中的网址前缀。
urlpatterns = patterns('karma.views',
(r'^$', 'homepage'),
(r'^logout/$', 'django.contrib.auth.views.logout', {'next_page': '/'}),
(r"^opportunities/nearby$", 'draw_map'),
)
Django尝试在您的案例'karma.views'
中查找与给定URL前缀相关的视图。在此模块中,没有'django.contrib.auth.views.logout'
,因此您获得ImportError
。
将注销URL移动到第二个块,例如:
urlpatterns += patterns('',
(r'^logout/$', 'django.contrib.auth.views.logout', {'next_page': '/'}),
)
这应解决您的问题。