簡體   English   中英

類型錯誤:“str”對象不可調用 - Django

[英]TypeError: 'str' object is not callable - Django

class IndexDetail(APIView):
    def get(self, request, *args, **kwargs):
        month = request.GET.get('month', None)
        current_month = datetime.datetime.now().month
        target_month = month if month is not None else current_month
        print(target_month,type(target_month))

我收到此錯誤:

Internal Server Error: /api/user/index/
.......
.......
  File "C:\Users\77922\PycharmProjects\Axepanda\user\views.py", line 34, in get
    print(target_month,type(target_month))
TypeError: 'str' object is not callable

嘿伙計們,當我寫這個“ type(target_month) ”時發生了錯誤,謝謝你幫我解決這個問題。

您為字符串分配了type 不要將變量分配給內置變量名。 如果您print(type)並輸出一個字符串,您肯定會知道。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM