【发布时间】:2021-04-05 15:34:27
【问题描述】:
在我在模板文件中添加 {% for %} 之前,我的网页运行良好。
这是我的 home.html 文件
<body>
<div>
<div>
{% if not status %}
<a href="/gmailAuthenticate" onclick="gmailAuthenticate()" title="Google">Google</a>
{% else %}
{% for item in contexto %}
<p>Your are verified</p>
<form id="myform" method="post" action="{% url 'logout' id=item.id %}/?next={{request.path }}">
{% csrf_token %}
<input type="hidden" name="name" value="value" />
<a onclick="document.getElementById('myform').submit();">disconnect</a>
</form>
{% endfor %}
{% endif %}
</div>
</div>
</body>
这是我的主页功能
def home(request):
status = True
contexto = CredentialsModel.objects.all()
if not request.user.is_authenticated:
return HttpResponseRedirect('admin')
storage = DjangoORMStorage(CredentialsModel, 'id', request.user, 'credential')
credential = storage.get()
try:
access_token = credential.access_token
resp, cont = Http().request("https://www.googleapis.com/auth/gmail.readonly",
headers={'Host': 'www.googleapis.com',
'Authorization': access_token})
except:
status = False
print('Not Found')
return render(request, 'index.html', {'status': status})
我检查了我的 errors.log 文件,但没有显示任何内容
【问题讨论】:
标签: python html django for-loop django-views