【问题标题】:NoReverseMatch error with socialauth in DjangoDjango中的socialauth出现NoReverseMatch错误
【发布时间】:2013-05-12 21:16:37
【问题描述】:

我一直在努力在 Django 项目中使用 socialauth 实现 facebook 身份验证。我不断收到此错误:

NoReverseMatch at /mysite/test
Reverse for 'socialauth_begin' with arguments '(u'facebook',)' and keyword arguments '{}' not found.
Request Method: GET
Request URL:    http://127.0.0.1:8000/mysite/test
Django Version: 1.5.1
Exception Type: NoReverseMatch
Exception Value:    
Reverse for 'socialauth_begin' with arguments '(u'facebook',)' and keyword arguments '{}' not found.

我相信我已经正确配置了 socialauth (this guide helped),但我不知道错误可能来自哪里。

我的模板 test.html 中的这一行给我带来了问题:

<a href="{% url 'socialauth_begin' 'facebook' %}">Login with Facebook</a>

我在网上找了很多地方,都没有找到合理的解决方案。

【问题讨论】:

  • socialauth_begin周围不带引号试试:{% url socialauth_begin "facebook" %}
  • 我试过了。似乎这个问题在旧版本的 Django 之前已经出现过。您可以看到我正在运行 1.5.1,这意味着引号是必要的
  • 检查,您是否在 urls.py 文件中包含了 social_auth 网址:url(r'', include('social_auth.urls')),,正如您提到的指南的第 4 步中所写的那样。还有,你有没有在 settings.py facebook 参数中设置:FACEBOOK_APP_IDFACEBOOK_API_SECRET
  • 是的,我都已经做过了。
  • 我使用 {% url 'socialauth_begin' "facebook" %} 这对我运行 1.5.1 有效

标签: python django socialauth


【解决方案1】:

使用新的 python-social-auth 和 django > 1.4 来拯救某人

使用这个:

{% url 'social:begin' 'facebook' %}

【讨论】:

  • 谢谢!这行得通。问题是新的 python-social-auth url 和旧的 django-social-auth url 之间的区别。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-07-01
  • 2017-09-05
  • 1970-01-01
  • 2013-08-08
  • 1970-01-01
相关资源
最近更新 更多