我想訪問我的模板中的根路徑變量,我該怎麼做? 到目前爲止,我有:django模板:訪問項目根路徑
{% if user.username == "" and request.path != "/login/" and request.path != "/" %}
<meta http-equiv="REFRESH" content="0;url=/login/">
{% else %}
我想編寫這樣的事:
{% if user.username == "" and request.path != projectRoot+"/login/" and request.path != projectRoot %}
<meta http-equiv="REFRESH" content="0;url=projectRoot+/login/">
{% else %}
我應該創建並從我的觀點發送此projectRoot變量,或者是有已經是一個變量?
提前許多感謝,
羅曼
有沒有你想通過這種方式登錄重定向一個特別的原因?這樣做有很多更好的方法(比如使用['login_required'](https://docs.djangoproject.com/en/dev/topics/auth/default/#the-login-required-decorator)裝飾器) – 2013-04-10 09:34:22