TypeError: 'str' object is not callable

38 views
Skip to first unread message

Salima Begum

unread,
Aug 30, 2021, 11:58:54 PMAug 30
to django...@googlegroups.com
Hi all,
In my project for each functionality I have written code for confirmation messages. For example
```
messages.success("Your ad is successfully posted")
```
Every functionality is breaking because of confirmation messages after deployment. How to fix it? Can anyone help me? 

Thank you
~Salima

Thomas Lockhart

unread,
Aug 31, 2021, 12:01:35 AMAug 31
to django...@googlegroups.com
Just guessing that you need to write

messages.success = “Your ad is successfully posted”

But without more information from you that is only a guess.

How is messages.success defined?

- Tom

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAMSz6bkOz8AXa7d%2BRFFjm0m8xmCLYOyLQNx6syy7tf-NsPTRhA%40mail.gmail.com.

Jacob Greene

unread,
Aug 31, 2021, 12:30:04 AMAug 31
to django...@googlegroups.com
You need to pass the request object as the first argument. 

Salima Begum

unread,
Aug 31, 2021, 12:50:33 AMAug 31
to django...@googlegroups.com
Hi Thomas,

The way I defined how i have written code for confirmation message
```
        messages.success(request, """Your Ad is successfully posted.""")
```
Thank you
~Salima

Salima Begum

unread,
Aug 31, 2021, 1:03:23 AMAug 31
to django...@googlegroups.com
Hi, Thank you for your response. 
 I have defined as below  I have mentioned snippet in all functionalities i am getting error in every functionality  " 'str' object is not callable ".Please help me to fix this issue.


```
        messages.success(request, """Your Ad is successfully posted.""")
```
Thank you 
~Salima

Lalit Suthar

unread,
Aug 31, 2021, 1:52:29 AMAug 31
to django...@googlegroups.com
go like this 

messages.add_message(request, messages.WARNING, "failure message")
return HttpResponse / render

Salima Begum

unread,
Aug 31, 2021, 1:57:58 AMAug 31
to django...@googlegroups.com
Hi all,
Actually this error is prompting because in my deployment site I am using django version 3.2. In this version they have some issue with messages so,  I referred to this document and I fixed it by adding one line in the settings.py file.

Lalit Suthar

unread,
Sep 2, 2021, 12:57:45 AMSep 2
to django...@googlegroups.com

Salima Begum

unread,
Sep 14, 2021, 12:24:18 AMSep 14
to django...@googlegroups.com
Hi,
 In my project for success confirmation messages I am using the Messages framework from Django. Here I am always getting errors in deployment server.


After deploying site.when i am continuously testing site. After some time I am getting the 'str' object is not callable error is raised. for success confirmation messages.
In views.py we are defining confirmation messages.
```
 messages.success(request, "Item is successfully removed.")

```
In settings.py 
```
MESSAGE_STORAGE = 'django.contrib.messages.storage.cookie.CookieStorage'
MESSAGE_LEVEL = message_constants.DEBUG
```

Django version 3.2.7

Can anyone please help me. how to fix this error I am facing this issue from long time back again and again same issue is raising. where I am going wrong i am not understanding could you please help me to fix this issue.

Thanks
~Salima

Reply all
Reply to author
Forward
0 new messages