user2657983
user2657983

Reputation:

Django Form Submit Update HTML

Instead of redirecting to a thank you page I would like to update the html of the current contact page after the response redirect. For example, when the user hits the submit button they are brought back to the same page, however, the page now has a

tag thanking them. I have no idea how to attempt this, or if it's possible.

Views.py

 if form.is_valid():
       return HttpResponseRedirect('/contact/')
       message = 'Success!'

HTML Page

{% if message %}
   <p>{{ message }}</p>
{% endif %}

Is this possible? Thanks

Upvotes: 0

Views: 467

Answers (1)

catavaran
catavaran

Reputation: 45555

You can use the messages framework:

if form.is_valid():
    messages.success(request, 'Success!')
    return HttpResponseRedirect('/contact/')

And then in the template:

{% if messages %}
    {% for message in messages %}
        <p>{{ message }}</p>
    {% endfor %}
{% endif %}

More advanced template can be found in the documentation.

Upvotes: 1

Related Questions