2
A
回答
3
你可以簡單地做:
@view_config(route_name='home', renderer='dashboard.jinja2')
def home_view(request):
if request.authenticated_userid is None:
# most people would probably opt to redirect to the login url
# here instead of rendering a response, but you asked
return render_to_response('login.jinja2', {}, request=request)
# user is logged in, so use the dashboard renderer
return {}
然而,金字塔是涼,有謂語。整齊。因此,我們可以使用effective_principals
謂詞基於2個不同的視圖之間進行調度用戶是否登錄:
from pyramid.security import Authenticated
@view_config(route_name='home', effective_principals=Authenticated, renderer='dashboard.jinja2')
def dashboard_view(request):
return {}
@view_config(route_name='home', renderer='login.jinja2')
def login_from_home_view(request):
return {}
+0
+1這個更高級的金字塔答案。謂詞是一種更好的方式來保持您的代碼清潔,並使更多的鎖定安全。 IE瀏覽器不能意外地通過條件檢查中的錯誤來授予視圖中的錯誤訪問權限,您的受保護的視圖將永遠不會執行。 –
1
重寫SQLAlchemy + URL dispatch wiki tutorial包含一個示例應用程序,它可以執行您想要的任務,以及密碼散列,授權和測試。這將在Pyramid 1.7中發佈(1.6.1是本文的最新版本)。您可以從本教程的src目錄獲取教程中完整的應用程序源代碼。
相關問題
- 1. 金字塔登錄用戶
- 2. 如何讓用戶使用網址儀表板登錄?username = xyz
- 3. 網址未更改,僅在登錄後呈現模板
- 4. 在金字塔中呈現模板和JSON
- 5. 根據用戶類型登錄後將顯示儀表板
- 6. 用戶登錄時留在儀表板中
- 7. 登錄後呈現模板?
- 8. 未知的謂詞值錯誤,同時呈現金字塔中的mako模板
- 9. 通過儀表板刪除用戶,但用戶仍然登錄?
- 10. Python金字塔與字母
- 11. Java掃描儀/陣列金字塔
- 12. 登錄處理網址
- 13. python函數在金字塔中表現不同?
- 14. 金字塔中的表單處理
- 15. Microstrategy - 根據用戶篩選儀表板
- 16. 儀表板成功登錄後Zabbix儀表板出錯
- 17. 小鬍子不在金字塔中呈現
- 18. 查詢用戶使用儀表板平臺登錄
- 19. 根據用戶輸入生成字母金字塔
- 20. 金字塔日誌記錄
- 21. Python金字塔解析JSON
- 22. Python cv2圖片金字塔
- 23. Python金字塔遍歷
- 24. Django登錄呈現重定向模板,但留在登錄URL
- 25. 儀表板無法使用管理員帳戶登錄
- 26. Django登錄表單 - 登錄到儀表板第二次
- 27. OpenCart安裝,無法登錄儀表板
- 28. 解析服務器儀表板登錄
- 29. 登錄系統和儀表板
- 30. 不能登錄到WordPress的儀表板
我不知道金字塔好,但我會假設你只是有路由功能中的聲明說:「如果用戶登錄,則渲染此模板,否則,渲染其他模板。」 – haliphax