12

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')),
)
4

1 回答 1

28

您在urlpatterns.

urlpatterns = patterns('karma.views',
  (r'^$', 'homepage'),
  (r'^logout/$', 'django.contrib.auth.views.logout', {'next_page': '/'}),
  (r"^opportunities/nearby$", 'draw_map'),
)

在您的情况下,Django 尝试查找与给定 URL 前缀相关的视图'karma.views''django.contrib.auth.views.logout'在这个模块中,没有ImportError.

将注销 URL 移动到第二个块,例如:

urlpatterns += patterns('',
  (r'^logout/$', 'django.contrib.auth.views.logout', {'next_page': '/'}),
)

那应该可以解决您的问题。

于 2012-06-06T09:24:54.040 回答