Layne Wu
Layne Wu

Reputation: 97

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))

I am getting this error :

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

Hey guys,the error occurred when I wrote this "type(target_month)" Thanks for helping me with this.

Upvotes: 0

Views: 1129

Answers (1)

Nicolas Gervais
Nicolas Gervais

Reputation: 36584

You assigned type to a string. Don't assign a variable to a built-in variable name. If you print(type) and it outputs a string, you'll know for sure.

Upvotes: 1

Related Questions