一个多月前,我成功地关注了这个博客条目:http ://www.artandlogic.com/blog/2014/04/tutorial-adding-facebooktwittergoogle-authentication-to-a-django-application/
当我创建一个新环境并重新创建这些步骤时,我现在no module named google_auth
在模板渲染期间遇到了一个导入错误。
它追溯到这一行:
<a href="{% url 'social:begin' 'google-oauth2' %}?next={{ request.path }}">Login</a>
看起来 django 没有在社交应用程序中寻找正确的模板处理?关于为什么这不再起作用的任何想法?
#settings.py
INSTALLED_APPS = (... , 'social.apps.django_app.default', ...)
AUTHENTICATION_BACKENDS = ('social.backends.google.GoogleOAuth2', 'django.contrib.auth.backends.ModelBackend')
TEMPLATE_CONTEXT_PROCESSORS = ('django.contrib.auth.context_processors.auth',
'django.core.context_processors.debug',
'django.core.context_processors.i18n',
'django.core.context_processors.media',
'django.core.context_processors.static',
'django.core.context_processors.tz',
'django.contrib.messages.context_processors.messages',
'social.apps.django_app.context_processors.backends',
'social.apps.django_app.context_processors.login_redirect')
#urls.py
urlpatterns = patterns('',
url('', include('social.apps.django_app.urls', namespace='social')),
url('', include('django.contrib.auth.urls', namespace='auth')),
url(r'^$', 'app.views.home', name='home'),
)
编辑:下面的完整追溯
Environment:
Request Method: GET
Django Version: 1.7
Python Version: 2.7.8
Installed Applications:
('django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'charts',
'social.apps.django_app.default',
'djcelery',
'kombu.transport.django')
Installed Middleware:
('django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
'social.apps.django_app.middleware.SocialAuthExceptionMiddleware',
'charts.middleware.SocialAuthExceptionMiddleware')
Template error:
In template charts/templates/base.html, error at line 69
No module named google_auth
59 : </ul>
60 : </li>
61 : <li>
62 : Hello, <strong>{{ user.get_full_name|default:user.username }}</strong>!
63 : </li>
64 : <li>
65 : <a href="{% url 'auth:logout' %}?next={{ request.path }}">Logout</a>
66 : </li>
67 : {% else %}
68 : <li>
69 : <a href=" {% url 'social:begin' 'google-oauth2' %} ?next={{ request.path }}">Login</a>
70 : </li>
71 : {% endif %}
72 : </ul>
73 : </nav>
74 : </head>
75 : <body>
76 : {% block content %}
77 : {% endblock %}
78 : <div id="footer">
79 : <center>
Traceback:
File "//anaconda/envs/analytics/lib/python2.7/site-packages/django/core/handlers/base.py" in get_response
111. response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "/charts/views.py" in home
743. context_instance=context)
File "//anaconda/envs/analytics/lib/python2.7/site-packages/django/shortcuts.py" in render_to_response
23. return HttpResponse(loader.render_to_string(*args, **kwargs), **httpresponse_kwargs)
File "//anaconda/envs/analytics/lib/python2.7/site-packages/django/template/loader.py" in render_to_string
174. return t.render(context_instance)
File "//anaconda/envs/analytics/lib/python2.7/site-packages/django/template/base.py" in render
148. return self._render(context)
File "//anaconda/envs/analytics/lib/python2.7/site-packages/django/template/base.py" in _render
142. return self.nodelist.render(context)
File "//anaconda/envs/analytics/lib/python2.7/site-packages/django/template/base.py" in render
844. bit = self.render_node(node, context)
File "//anaconda/envs/analytics/lib/python2.7/site-packages/django/template/debug.py" in render_node
80. return node.render(context)
File "//anaconda/envs/analytics/lib/python2.7/site-packages/django/template/loader_tags.py" in render
126. return compiled_parent._render(context)
File "//anaconda/envs/analytics/lib/python2.7/site-packages/django/template/base.py" in _render
142. return self.nodelist.render(context)
File "//anaconda/envs/analytics/lib/python2.7/site-packages/django/template/base.py" in render
844. bit = self.render_node(node, context)
File "//anaconda/envs/analytics/lib/python2.7/site-packages/django/template/debug.py" in render_node
80. return node.render(context)
File "//anaconda/envs/analytics/lib/python2.7/site-packages/django/template/defaulttags.py" in render
312. return nodelist.render(context)
File "//anaconda/envs/analytics/lib/python2.7/site-packages/django/template/base.py" in render
844. bit = self.render_node(node, context)
File "//anaconda/envs/analytics/lib/python2.7/site-packages/django/template/debug.py" in render_node
80. return node.render(context)
File "//anaconda/envs/analytics/lib/python2.7/site-packages/django/template/defaulttags.py" in render
444. url = reverse(view_name, args=args, kwargs=kwargs, current_app=context.current_app)
File "//anaconda/envs/analytics/lib/python2.7/site-packages/django/core/urlresolvers.py" in reverse
517. app_list = resolver.app_dict[ns]
File "//anaconda/envs/analytics/lib/python2.7/site-packages/django/core/urlresolvers.py" in app_dict
329. self._populate()
File "//anaconda/envs/analytics/lib/python2.7/site-packages/django/core/urlresolvers.py" in _populate
303. lookups.appendlist(pattern.callback, (bits, p_pattern, pattern.default_args))
File "//anaconda/envs/analytics/lib/python2.7/site-packages/django/core/urlresolvers.py" in callback
231. self._callback = get_callable(self._callback_str)
File "//anaconda/envs/analytics/lib/python2.7/site-packages/django/utils/lru_cache.py" in wrapper
101. result = user_function(*args, **kwds)
File "//anaconda/envs/analytics/lib/python2.7/site-packages/django/core/urlresolvers.py" in get_callable
101. not module_has_submodule(import_module(parentmod), submod)):
File "//anaconda/envs/analytics/lib/python2.7/importlib/__init__.py" in import_module
37. __import__(name)
Exception Type: ImportError at /
Exception Value: No module named google_auth