problem with redirect

I’m sorry, but I’m not following what you’re trying to say here.

Let’s take a step back to basics for a moment:

A browser issues a request.

A web server receives the request and passes it along to Django

Django uses the url in the request to find which view to call - and calls that view

The view receives the request and returns a response.

That response can be one of:

  • HttpResponse (perhaps from the output of a call to render)
  • HttpResponseRedirect
  • FileResponse
  • JsonResponse
  • and others.

Django returns that Response object back out through the web server to the browser.

What the browser does with that response depends upon how the request was made (normal browser request or AJAX), and the type of response.


Now, when you include forms into this mix, it extends this pattern by an extra exchange:

Request #1 - get the form to be filled out
Response #1 - the empty form

Request #2 - the filled-out form
Response #2 - typically either:

  • A redirect going to a different page, which could be the same url as Request # 1
  • The same form, but with errors indicated in the page showing what needs to be corrected to submit the form.

So yes, you could define two different URLs for the same view. One like you have now for the blank form, and a second url that includes a parameter to use to populate the form with the calculated BMI. It’s then up to you to write a view capable of handling both types of requests.