Questions tagged [django-messages]

Notification messages framework for Django

The messages framework

Quite commonly in web applications, you need to display a one-time notification message (also known as “flash message”) to the user after processing a form or some other types of user input.

For this, Django provides full support for cookie- and session-based messaging, for both anonymous and authenticated users. The messages framework allows you to temporarily store messages in one request and retrieve them for display in a subsequent request (usually the next one). Every message is tagged with a specific level that determines its priority (e.g., info, warning, or error).

155 questions
2
votes
0 answers

Keep django messages until they are deleted

How to keep django messages alive (in the django admin), until they are deleted by a further action? I use the django messages to remind the user of a required activity. The message should displayed until the required activity is done. For one view,…
T. Christiansen
  • 1,036
  • 2
  • 19
  • 34
1
vote
0 answers

Django not showing messages after redirect

I'm using Django 4.0.9, and I'm trying to show a message using django-messages after a user has been created and after it has been deleted. Using prints I can see that the messages get created when the create/delete form executes, but when the…
Fefe
  • 13
  • 3
1
vote
1 answer

Doesn't "__str__()" work properly in "admin.py" for Django Admin?

For example, I define __str__() in Person model as shown below: # "models.py" from django.db import models class Person(models.Model): first_name = models.CharField(max_length=20) last_name = models.CharField(max_length=20) def…
Super Kai - Kazuya Ito
  • 22,221
  • 10
  • 124
  • 129
1
vote
0 answers

Django: How to show a message in a custom admin action with a download?

I'm defining a custom admin action called Download CSV. In this action I want to download a .csv file and show a message to the user. I have not been able to make both happen. I tried this way: @admin.action(description=gettext_lazy("Download…
1
vote
1 answer

Is there a way to show Django messages in Django admin site?

I need to display a Django message on the Django admin index site. I am looking for a way to add certain conditions for the message to be displayed and pass it to Django index site. Is there a way to achieve that?
1
vote
0 answers

Django: Messages enum options

I have a view that handles a variety of forms to manage objects (e.g rename, delete, etc.). For each action I want to define a success and error message such that I do not need to have the message text written directly in the view. Rather I want to…
micshapicsha
  • 187
  • 3
  • 12
1
vote
1 answer

I have Syntax Error When I edit django messages

I want to edit django error mesages like class error mesages.But when I add if controller in HTML documents, I meet syntax error Note: (just when I use if controller I have syntax error) Views content; from django.contrib import messages if…
Hamit
  • 15
  • 5
1
vote
1 answer

How to add alert messages in Django LoginRequiredMixin

So i am using LoginRequiredMixin in Django for some of my feature that require users to logged in. but since i am using class based views and there's no request i don't know how to add django.contrib.messages in my view and template. Is there a way…
Malik
  • 236
  • 2
  • 3
  • 14
1
vote
2 answers

How to remove the default successful message displayed in "Change" page in Django Admin?

I have a model Document, and the admin can upload an image to a FileField. When a document/image is successfully uploaded, I also save a sha256 "fingerprint" of the image to test if an admin tries to upload a duplicate image. If a duplicate image is…
user1045680
  • 815
  • 2
  • 9
  • 19
1
vote
1 answer

Django Messages show up only in admin

I have set up a django message that gets displayed when the user logs in, but the messages show up only in the admin. accounts/views.py def login_page(request): form = LoginForm(request.POST or None) context = { 'form':form } …
user11929397
1
vote
1 answer

Django: send message to all users (sessions)

I have a python+django project and want to implement following functionality: by certain trigger (at certain time or by manual admin action) show message to all active users (i.e. to all sessions). Webpush seems unnecessary here as far as django has…
Vitaly Trifanov
  • 631
  • 2
  • 8
  • 17
1
vote
1 answer

How can I count the messages coming from a view inside a template?

I'm using Django's messages framework to pass messages from my view functions to my templates. I want a template to contain some HTML only if the number of messages is greater than 1. Is there a way to do this? I've tried the following: {% if…
Michael Hoffmann
  • 2,411
  • 2
  • 24
  • 42
1
vote
1 answer

Django message with breakline and redirect url inside

I would like to improve my django message with some things : add a breakline in the text and add an url using django reverse url. This is my message : messages.error(self.request, _( f"The link to download the document has expired. Please request…
ChocoBomb
  • 301
  • 4
  • 15
1
vote
1 answer

Django order of message tags

I wonder if it is possible to change the order of the message tags of a django message with extra tags. from django.contrib import messages messages.success(request, 'success message', extra_tags='safe') And in my template I use {% if messages %} …
Philipp
  • 406
  • 5
  • 15
1
vote
1 answer

Django messages - check if a message already exists before adding

Is it possible to check if a django message and contents exist before adding another message? In my example I am peforming a try - except in a loop, and if an exception occurs I add a message, but I only want the message to appear once, not for each…
AlexW
  • 2,843
  • 12
  • 74
  • 156
1 2
3
10 11