- 論壇徽章:
- 0
|
[django] 一個奇怪的問題
我在用django 實現(xiàn)用戶權(quán)限的功能,
碰到這樣一個奇怪的問題,
我在基模板中:
pt/base.html- ....
- {% if user.is_authenticated %}
- Hello, {{ user.username }}
- <a href="/accounts/logout/"> Logout </a>
- <br> <a href="/pt/change_password"> Change Password </a>
- {% else %}
- <a href="/accounts/login/"> Login </a>
- {% endif %}
- ....
復(fù)制代碼 然后, 在每個模板中, 繼承這個模板,- {% extends "pt/base.html" %}
復(fù)制代碼 在我已經(jīng)登錄的情況下,
我在 views.py 中, 分別利用下面兩句顯示的頁面, 得到的結(jié)果不同- (1) return render_to_response('pt/ship_index.html')
- (2) return direct_to_template(request, template = 'pt/ship_index.html')
復(fù)制代碼 利用(1), 得到的頁面顯示沒有登錄,
利用(2), 得到的頁面顯示登錄.
請問為何這樣?
應(yīng)該如何用比較好的方法處理這個問題?
我各個頁面中都是使用 render_to_response 的,
而且很多情況下, 用(2) 解決不了我的問題..
如何辦呢? |
|