使用 Django自帶的 auth 用戶驗證功能,編寫函數,使用 is_authenticated 檢查用戶是否登錄,結果報錯:
TypeError at / 'bool' object is not callable
編寫函數如下:
查詢相關資料,發現 is_authenticated 是屬性而不是方法,我們應該把括號去掉,這樣就沒什么問題了。
將
if request.user.is_authenticated():
改為
if request.user.is_authenticated: