Sorry for my poor English, I will try to describe my problem as best as possible. I am using Django 1.5 with Python 3.2. I use django.contrib.messages to display messages to users after they are redirected. If I try to load a page redirecting to another page with a message, after several attempts, it does not delete previous messages (only on the last previous page). So, I see two identical messages. This only happens on Google Chrome (and Cromium). Never in FireFox or Opera. Regardless of whether the messages are saved as cookies or in the session. The view function is called twice, but I donβt know why and what exactly has Chrome (???) in it.
I recorded a video: http://www.youtube.com/watch?v=nXtQ0uj1Hbw&feature=youtu.be .
Added later ...
Ok I started a new project just for this (the "mysite" project containing one application inside it called "test_app"):
contents of mysite / urls.py:
from django.conf.urls import patterns, include, url urlpatterns = patterns('', url(r'^ms', include('test_app.urls', namespace="testapp")), )
contents of test_app.py
from django.conf.urls import patterns, url urlpatterns = patterns('test_app.views', url(r'/go-away/$', 'go_away', name='go-away'), url(r'/come-here/$', 'come_here', name='come-here'), )
contents of test_app / views.py
from django.shortcuts import render from django.core.urlresolvers import reverse from django.http import HttpResponseRedirect from django.contrib import messages import random def go_away(request): messages.info(request, 'FORBIDDEN PLACE! Float: %f' % random.random()) return HttpResponseRedirect(reverse('testapp:come-here')) def come_here(request): return render(request, 'testapp/template.html', {})
contents of testapp / templates / testapp / template.html
{% if messages %} <ul> {% for message in messages %} <li>{{ message }}</li> {% endfor %} </ul> {% else %} There was no redirection. {% endif %}
besides all this, I added .py (at and) to my settings:
# Context processors TEMPLATE_CONTEXT_PROCESSORS = { 'django.contrib.messages.context_processors.messages', }
configured database (mysite / mysite.db) and even ran the command "python3 manage.py syncdb"
Nothing else has been done. You can easily reproduce this.
My software: - Python 3.2 - Django 1.5 - Apache 2.2 with MOD_WSGI compiled from source. - All this under Linux Mint 14.
What you should see at the end: http://www.youtube.com/watch?v=3L27iwP1PqM&feature=youtu.be the quality is not the greatest, but I did paste the code here.
As you can see, the floats are all different, this means that messages are added only during one request and are not displayed on other pages. And this means that, as I understand it, the view function was executed twice, ignoring the first redirect.
PS: This is the same with a session if you save messages manually in the request.session.messages list. I only have this problem when I use Chrome or Chromium. Opera, as you can see, works great.