I successfully followed along this blog entry more than a month ago:http://www.artandlogic.com/blog/2014/04/tutorial-adding-facebooktwittergoogle-authentication-to-a-django-application/
When I created a new environment, and recreated the steps, I'm now getting an import error, no module named google_auth
during template rendering.
It traces back to this line:
<a href="{% url 'social:begin' 'google-oauth2' %}?next={{ request.path }}">Login</a>
It looks like django is not looking in the social app for the correct template processing? Any ideas on why this is no longer working?
#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
If it is an option for you, I would propose to use django-allauth instead. I used both django-allauth and Python Social Auth and personally find it much easier to work with django-allauth. So if you have a chance, give it a try
This is one difficult problem.
The error, the first line of the stack trace gives a clue: "Traceback: .... wrapped_callback ...."
The social.apps.django_app.views.auth
view is called and is wrapped in decorator psa
. This eventually produces the error but I think django.core.handlers.base.get_response
is hiding the actual exception source. I think the reraise makes the stack trace incomplete at the moment.
The exception probably occurs in from social.backends.utils.get_backend
. But it's hard to debug from a distance.
Can you comment out the try-catch around the line response = wrapped_callback(request, *callback_args, **callback_kwargs)
in the file django.core.handlers.base
. What is the new stack trace you get when loading the page?
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