How to use messages in other than views.py

I want to use messages in my tasks.py file but I don’t know what to put in the request field.

You can’t use contrib.messages like that out of the box. You’ll need to write some logic to store and fetch the messages for the user on each request. Alternatively, you can look for a package that does this for you. I haven’t used one that does this exactly so I can’t make a specific recommendation, but the djangopackages.org site is a fantastic resource for this. Here’s the grid you likely want: Django Packages : Notification