djangoのデフォルトモデルUserを使用しています(django-facebookを使用しているため)。テンプレートでユーザー認証が機能しません。コードは次のとおりです。
{% if request.user.is_authenticated %}
Welcome, {{ request.user.first_name }}
<a href="/logout">logout</a>
{% else %}
<form action="{% url facebook_connect %}?facebook_login=1" method="post">
<a href="javascript:void(0);" style="font-size: 20px;" onclick="F.connect(this.parentNode);">
<img src="/media/images/site/facebook_login.png" alt="facebook_login" class="facebook_login_button"/>
</a>
<input type="hidden" value="{{ request.path }}" name="next" />
</form>
{% endif %}
ビューからcontext_instanceを渡しました:
return render_to_response('index.html', context, context_instance=RequestContext(request))
しかし、それでも機能しません。ご協力いただきありがとうございます!
編集:
ユーザーはdjango-facebook(auth_userテーブルに挿入)で正常にログインし、データは表示されますが、ユーザーがログアウトするとデータが消え、上記の編集済みコードに表示されているログインフォームが表示されません。
ユーザーのログインとログアウトに使用する完全なビューは次のとおりです。
def logout_view(request):
logout(request)
return HttpResponseRedirect('/')
def signin(request):
username = request.POST['username']
password = request.POST['password']
user = authenticate(username=username, password=password)
if user is not None:
if user.is_active:
login(request, user)
return HttpResponseRedirect('/')
else:
# TO RETURN ERROR
return HttpResponseRedirect('/')
else:
# TO RETURN ERROR
return HttpResponseRedirect('/')
request.user.first_nameからリクエストを削除すると、エラーが表示されます。
プロジェクト設定でAUTH_PROFILE_MODULEを設定する必要があります
それは私が得ることができるすべての詳細についてです。