[Django]-Confirming generic FormView POST success back to user with POST data

5👍

Include the data as GET parameters in your success url.

def get_success_url(self):
   url = reverse('success')
   # maybe use urlencode for more complicated parameters
   return "%s?foo=%s" % (url, self.request.POST['bar'])

Then in your template, access the parameters in the GET data.

foo: {{ request.GET.foo }}

2👍

I was trying to figure this out too and a simple solution is to use:

from django.contrib import messages

In get_success_url(self) you can write

def get_success_url(self)
    messages.add_message(self.request, messages.SUCCESS, 'Contact Successfully Updated!')
    return reverse('contacts:contact_detail', args=(self.get_object().id,))

And in your template you can access this message via

{% for message in messages %}
    {{ message }}
{% endfor %}

1👍

One way to accomplish what you’re looking to do would be through the use of Sessions. Store whatever values you need on the user’s session object, and access them from within the SuccessView. Check out the Django session documentation for more details.

👤fourk

Leave a comment