1

I have a problem with my Django application.

What I want to do, in theory, is simple, but I'm not getting it. I am working with "CLASS BASED VIEWS". What I want to do is the following, I intend to have a page with my form, so when the user clicks on the button to submit the information Django has to perform some mathematical calculations with the information that was on the form and, after calculating everything, should redirect the user to a new page with the result of the calculations.

Would someone give me a light on how to do this? Below is a graphic example of the process.

CLICK TO SEE THE PROCESS

Algorithm:

  1. Capture information using form - VIEW 01 / TEMPLATE 01
  2. Perform some mathematical calculations with submitted information
  3. Show results on another page - VIEW 02 / TEMPLATE 02
  • Hi, I am just wondering ... would this be helpful ? https://stackoverflow.com/questions/11494483/django-class-based-view-how-do-i-pass-additional-parameters-to-the-as-view-meth – StyleZ May 13 '21 at 22:40

1 Answers1

1

This might be helpful.

After validating and saving form:

if form.is_valid():
    form.save()

you can redirect the user to another path with GET parameters like this:

return redirect(reverse('view_02_name_in_urlconf', kwargs={"key": your_calculation}))

So, you can do like this:

if form.is_valid():
    form.save()
    
    # do some calculations with form over here

    return redirect(reverse('view_02_name', kwargs={"key": your_calculation}))

Url configuration for view_02 must look like this:

url(r'^/(?P<key>[0-9]+)/$', views_02.view_02_name_in_view.py, name='view_02_name')

View and its functions can be named after any string you like.

Then you can show the calculated data in view_02. Or you can reverse with raw data and do calculations in view_02.

Thanks for reading.

pullidea-dev
  • 1,768
  • 1
  • 7
  • 23