欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

Django錯(cuò)誤:TypeError at / 'bool' object is not callable解決

 更新時(shí)間:2019年08月16日 11:18:35   作者:希希里之海  
這篇文章主要介紹了Django 錯(cuò)誤:TypeError at / 'bool' object is not callable解決,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下

使用 Django自帶的 auth 用戶驗(yàn)證功能,編寫函數(shù),使用 is_authenticated 檢查用戶是否登錄,結(jié)果報(bào)錯(cuò):

TypeError at / 'bool' object is not callable  

編寫函數(shù)如下:

def index(request, pid=None, del_pass=None):
  if request.user.is_authenticated():
    username = request.user.username
    useremail = request.user.email
  messages.get_messages(request)
  template = get_template('index.html')
  html = template.render(context=locals(), request=request)
  return HttpResponse(html)

查詢相關(guān)資料,發(fā)現(xiàn) is_authenticated 是屬性而不是方法,我們應(yīng)該把括號(hào)去掉,這樣就沒什么問題了。

將 

if request.user.is_authenticated():

改為

 if request.user.is_authenticated:

以上就是本文的全部內(nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

最新評(píng)論