django allAuth'要求'在例如使用provider_login_url时出错main.html中

时间:2013-01-28 11:58:43

标签: django django-authentication

害怕这是一个新手问题。

我正在我的主页上尝试使用社交登录链接,在我的模板中使用此代码:

{% load i18n %}
{% load static %}
{% load socialaccount %}
{% load account %}
{% load url from future %}
{% get_static_prefix as STATIC_PREFIX %}
...
<a href="{% provider_login_url 'facebook' method='js_sdk' %}"><img src='{{ STATIC_PREFIX }}img/facebookText.png' alt="facebook connect"></a>
<a href="{% provider_login_url 'google' method='js_sdk' %}"><img src='{{ STATIC_PREFIX }}img/googleText.png' alt="google connect"></a>
<a href="{% url 'account_login' %}"><img src='{{ STATIC_PREFIX }}img/idText.png' alt="Regular login"></a>

我已确保正确指定了我的网站ID(如[here] [1]所述)。

我已按照本教程[2]和本[指南] [3]中的建议在settings.py中指定了设置:

INSTALLED_APPS = (
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.sites',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    # Uncomment the next line to enable the admin:
    # Uncomment the next line to enable admin documentation:
    # 'django.contrib.admindocs',
    'django_tables2_reports',
    'subscription',
    'django_tables2',
    'allauth',
    'allauth.account',
    'allauth.socialaccount',
    'allauth.socialaccount.providers.facebook',
    'allauth.socialaccount.providers.google',
    #'allauth.socialaccount.providers.linkedin',
    #'allauth.socialaccount.providers.openid',
    # 'allauth.socialaccount.providers.twitter',
    'django.contrib.admin',

)

TEMPLATE_CONTEXT_PROCESSORS = (
                               "django.core.context_processors.request",
                               'django.contrib.auth.context_processors.auth',
                               'django.core.context_processors.static',
                               "django.core.context_processors.debug", 
                               "django.core.context_processors.i18n", 
                               "django.core.context_processors.media",
                                "allauth.account.context_processors.account",
                                "allauth.socialaccount.context_processors.socialaccount",

                                )

AUTHENTICATION_BACKENDS = (

    # Needed to login by username in Django admin, regardless of `allauth`
    "django.contrib.auth.backends.ModelBackend",

    # `allauth` specific authentication methods, such as login by e-mail
    "allauth.account.auth_backends.AuthenticationBackend",

)

我还指定在登录后,用户将被定向到我的主页:

LOGIN_REDIRECT_URL="/"

但是在访问我的主页时遇到此错误(远端模板提供的页面): 模板渲染期间出错

In template C:\Users\Andy\Desktop\business\app\static\templates\base.html, error at line 40
request
30          </style>
31  </head>
32  <body class="{% block body_class %}{% endblock %}">
33  <div align="right">
34  {% if user.is_authenticated %}
35  {% user_display user as user_display %}
36  {% blocktrans %}{{ user_display }} logged in{% endblocktrans %}
37  <a href="{% url 'account_logout' %}">Sign Out</a>
38  {% else %}
39  <img src='{{ STATIC_PREFIX }}img/loginText.png' alt="login">
40  <a href="{% provider_login_url 'facebook' method='js_sdk' %}"><img src='{{ STATIC_PREFIX }}img/facebookText.png' alt="facebook connect"></a>
41  <a href="{% provider_login_url 'google' method='js_sdk' %}"><img src='{{ STATIC_PREFIX }}img/googleText.png' alt="google connect"></a>
42  <a href="{% url 'account_login' %}"><img src='{{ STATIC_PREFIX }}img/idText.png' alt="Regular login"></a>
43  {% endif %}
44  </div>
45  
46  
47  
48  
49  {% block body %}
50  {% block content %}{% endblock %}

非常感谢帮助:)我怀疑我的View需要向我的html提供与此provider_login_url相关的其他信息。

1 个答案:

答案 0 :(得分:3)

回答我自己的愚蠢问题,

我的主页查看是:

def home(request):
    """Main listing."""
    return render_to_response("main/index.html", "")

现在是:

def home(request):
    """Main listing."""
    return render_to_response("main/index.html", context_instance=RequestContext(request))