我已经按照此处的说明完成了本教程:
在这里
但有些地方我无法理解。
当我使用 Facebook 帐户登录时,我也可以轻松访问我的管理页面并且我希望它发生(因为它不安全),那么有没有办法解决这个问题?
如果我想将该注册用户带到另一个模板,我只能在我的 url 调度程序中使用 direct_to_template 方法,这是一个示例:
url(r'^tags$', direct_to_template, {'template' : 'user.html' })
,
还有另一种方法吗?
最后为了更清楚,这里是我的项目的一些片段:
网址.py
urlpatterns = patterns('',
#All Auth URLS
url(r'^accounts/', include('allauth.urls')),
url(r'^accounts/profile/', direct_to_template, { 'template' : 'profile.html' }),
#nav urls
url(r'^$','fb.views.home', name="home"),
url(r'^tags$', direct_to_template, {'template' : 'tags.html' }),
视图.py
def home(request):
return render_to_response("base.html", locals(), RequestContext(Context))
base.html
......
{% block body %}
{% block content %}
{% if user.is_authenticated %}
{{ user.username }} <p> you are logged in </p>
<p><a href="/accounts/logout/" >Logout </a></p>
{% else %}
<p> you are not authenticated : </p>
<a href="/accounts/facebook/login/" >Login with Facebook </a>
{% endif %}
{% endblock content %}
{% endblock body %}
...
profile.html
...
{% block content %}
{% if user %}
<h1>Welcome, {{user.first_name}}</h1>
<p>Following is the Extra information that facebook has provided to allauth:</p>
{% for account in user.socialaccount_set.all %}
<p>First Name: {{ account.extra_data.first_name }}</p>
<p>Last Name: {{ account.extra_data.last_name }}</p>
<p>Profile Link: <a href="{{ account.extra_data.link }}">{{ account.extra_data.link }}</a></p>
{% endfor %}
{% endif %}
<a href="/tags"> Go to tags</a>
{% endblock content %}
{% endblock body %}
标签.html
{{user.socialaccount_set.all.0.get_avatar_url}} <br/>
{{user.socialaccount_set.all.0.uid}} <br/>
{{user.socialaccount_set.all.0.get_provider_account }} <br/>
最后提前感谢您的帮助。