1

ここで説明したように、このチュートリアルを実行しました:

そしてここ

しかし、私が理解できないいくつかの点があります。

Facebookアカウントを使用してログインすると、管理ページにも簡単にアクセスできますが、(安全ではないため)アクセスしたいのですが、それを修正する方法はありますか?

その登録済みユーザーを別のテンプレートに移動したい場合は、URL ディスパッチャーの direct_to_template メソッドでのみ実行できます。例を次に示します url(r'^tags$', direct_to_template, {'template' : 'user.html' })

それを行う別の方法はありますか。

最後に、より明確にするために、ここに私のプロジェクトの一部を示します。

urls.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 %}

tags.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/>

最後に、ご協力いただきありがとうございます。

4

1 に答える 1

0

秘密は次のとおりです。

ログイン後、ユーザーはリクエストオブジェクトに隠れていたため、ビューは次のようになります。

def home(request):
    user = request.user
    return render_to_response("base.html", locals(), RequestContext(Context))

これで問題は解決しましたが、Context User オブジェクトが匿名だった理由が気になります。

この質問をしている理由は、単純な認証では最後のユーザー オブジェクトが要求ユーザーと同じ値を持つためです。

于 2013-01-08T14:12:15.740 に答える