Url namespace not being registered for python social auth

允我心安 提交于 2020-01-06 14:47:17

问题


I have a legacy application using django 1.4.2 and python-social-auth.

I have the app installed

INSTALLED_APPS = (
     ...
     'social.apps.django_app.default',
     ...
)

The backends:

AUTHENTICATION_BACKENDS = (
    'social.backends.facebook.FacebookAppOAuth2',
    'social.backends.facebook.FacebookOAuth2',
    'social.backends.google.GoogleOAuth',
    'social.backends.google.GoogleOAuth2',
    'social.backends.google.GoogleOpenId',
    'django.contrib.auth.backends.ModelBackend',
)

More settings...

SOCIAL_AUTH_FACEBOOK_ID = ''
SOCIAL_AUTH_FACEBOOK_SECRET = ''

SOCIAL_AUTH_ENABLED_BACKENDS=('facebook', 'google')
SOCIAL_AUTH_DEFAULT_USERNAME= lambda u: slugify(u)

And in my root url :

urlpatterns += patterns('',
    url('', include('social.apps.django_app.urls', namespace='social'))

But I still get this error:

Template error:
In template /home/matias/Proyectos/apuntes/copias/templates/login.html, error at line 9
 9 : <p>Ingresá con tu cuenta de <a class="login facebook" href=" {% url 'social:begin' 'facebook' %} {% if request.GET.next %}?next={{ request.GET.next }}{% endif %}">Facebook</a> </p>
Exception Type: NoReverseMatch at /login
Exception Value: u"'social" is not a registered namespace

I don't know what's missing. As far as I can tell I have everything right.

The quoting in the error messages worries me. But the urls.py is fine so maybe it's django formatting being funny.

Any pointer?


回答1:


Version missconfiguration. For django lower than 1.5 you need to add:

{% load url from future %} 

Right up the template.

I was confused because that's not listed in the section about url dispatching in the docs https://docs.djangoproject.com/en/1.4/topics/http/urls/#defining-url-namespaces.

I also had no idea the load templatetag had a from argument...



来源:https://stackoverflow.com/questions/21942622/url-namespace-not-being-registered-for-python-social-auth

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!