我遇到了我的django站點的用戶身份驗證問題。我有一個似乎可以工作的登錄屏幕。當用戶點擊登錄時,我打電話給django.contrib.auth.login
,它似乎工作正常。但是在後續頁面上並不知道有用戶登錄。示例{% user.is_authenticated %}
爲false。還有一些菜單功能可供登錄用戶使用,如my-account
和logout
。除登錄頁面外,這些功能不可用。這真的很奇怪。Django中的用戶上下文
這似乎是一個用戶上下文問題。但我不確定我應該如何傳遞上下文以確保我的登錄穩定。 base.html文件的Does anyone know at could be going on here? Any advice?
--------- ------------部分
<!--- The following doesn't register even though I know I'm authenticated -->
{% if user.is_authenticated %}
<div id="menu">
<ul>
<li><a href="/clist">My Customers</a></li>
<li><a href="#">Customer Actions</a></li>
<li><a href="#">My Account</a></li>
</ul>
</div>
{% endif %}
---------我的看法。 PY -----------------
# Should I be doing something to pass the user context here
def customer_list(request):
customer_list = Customer.objects.all().order_by('lastName')[:5]
c = Context({
'customer_list': customer_list,
})
t = loader.get_template(template)
return HttpResponse(t.render(cxt))
偉大的作品!謝謝! – codingJoe