我刚刚用我的简单 django 应用程序配置了 fandjango。
文件如下:
VIEWS.PY
from django.http import HttpResponse
from django.shortcuts import render
from fandjango.decorators import facebook_authorization_required
@facebook_authorization_required()
def home(request):
return render(request, 'home.html', {'facebook_user': request.facebook.user})
HOME.HTML
{% if facebook_user.first_name %}
You are:<br>
{{ facebook_user.first_name }} {{ facebook_user.last_name }}.
<br>ID: {{ facebook_user.facebook_id }}
<br>YOUR URL: {{ facebook_user.profile_url }}
<br><img src="http://graph.facebook.com/{{ facebook_user.facebook_id }}/picture?type=large">
{% else %}There's a problem here.{% endif %}
现在,当我转到 http://apps.facebook.org/myapplicationname 时我允许应用程序访问帐户信息,我看到了 home.html。
但是(这是个大问题)有时我会看到我的所有信息(如果条件为真)但有时我看不到我的信息并且我看到“这里有问题”。数据库中数据正常。
我已经用其他帐户检查过了,但仍然存在这个神秘的问题。
请您参考如下方法:
而不是做
{% if facebook_user.first_name %}
检查
{% if facebook.user %}
如果他被授权,那将实际检查用户;第一个可能会给您随机错误 - 某些用户可能缺少名字 -。
