I get the ImportError "No module named django.contrib.auth"
both when I try to use the django.shortcuts
redirect
function and when I try to use:
(r'^logout/$', 'django.contrib.auth.views.logout', {'next_page': '/'}),
I figure it can't be a coincidence that the only place I'm hitting this error is in places where the page is redirected, but maybe it is. I know that the user isn't actually getting logged out, so the error happens before you even get to any redirect code.
Below is my urls.py file.
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')),
)
You are mixing up URL prefixes in your urlpatterns
.
urlpatterns = patterns('karma.views',
(r'^$', 'homepage'),
(r'^logout/$', 'django.contrib.auth.views.logout', {'next_page': '/'}),
(r"^opportunities/nearby$", 'draw_map'),
)
Django tries to find views relative to the given URL prefix, in your case 'karma.views'
. Inside this module, there is no 'django.contrib.auth.views.logout'
, hence you get the ImportError
.
Move the logout URL to a second block, e.g.:
urlpatterns += patterns('',
(r'^logout/$', 'django.contrib.auth.views.logout', {'next_page': '/'}),
)
That should resolve your issue.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With