Django: messages.error doesn't work with redirect('/')

40 views Asked by At

I'm so confused in templates main page I have:

{% for message in messages %}                                     
 {% if message.level == DEFAULT_MESSAGE_LEVELS.ERROR %}           
  <div class="alert alert-danger" role="alert">{{ message }}</div>
 {% endif %}                                                      
{% endfor %}                                                      

but the message is not printed. in views.py I have

def my_form(request):

 if not str(request.POST['name']):                               
     messages.error(request,'error message.')                          
     return redirect('/') 

                                   

and in myapp urls.py

path('', views.index, name='index'),                                   
re_path(r'^MyForm/$', views.my_form, name='my_form')

        

and in the general urls.py

re_path(r'^', include('myapp.urls'), name='home') 

what could be the issue, the log file shows nothing

0

There are 0 answers