django - How to show status about submitted form when using POST-Redirect-GET pattern? -


the post-redirect-get pattern recommended when submitting forms, in order void resending post data if user refresh. may done in view handling post data code like:

def get_name(request):     if request.method == 'post':         form = nameform(request.post)         if form.is_valid():             interesting_information = 'feedback after form submit'             return httpresponseredirect('/thanks/') 

but using scheme, how possible show interesting_information user, may example status information based on submitted form?

you can use django's messages framework set message in form handling view:

from django.contrib import messages messages.success(request, 'feedback after form submit') 

and display user on /thanks/ page:

{% if messages %} <ul class="messages">     {% message in messages %}     <li{% if message.tags %} class="{{ message.tags }}"{% endif %}>{{ message }}</li>     {% endfor %} </ul> {% endif %} 

you'll need make sure follow steps in "[enabling messages]"(https://docs.djangoproject.com/en/1.8/ref/contrib/messages/#enabling-messages) section of docs first.


Comments

Popular posts from this blog

html - Outlook 2010 Anchor (url/address/link) -

javascript - Why does running this loop 9 times take 100x longer than running it 8 times? -

Getting gateway time-out Rails app with Nginx + Puma running on Digital Ocean -