0

I have a django app samplesubmission with two different views. The index view (localhost:8000/samplesubmission/) lists the last 5 samples and an add view (localhost:8000/samplesubmission/add/), which adds a new sample. If everything works, I return the index view.

return index(request)

This works fine, only the url in the browser still says localhost:8000/samplesubmission/add/ so, if I hit reload, I am already at the form to add a new sample...

Just wondering, how to change the url in the browser.

Sorry, for not presenting a minimal working example, but I am not sure, what I will need for this question.

drmariod
  • 11,106
  • 16
  • 64
  • 110

2 Answers2

2

You should use redirect() for that:

https://docs.djangoproject.com/en/dev/topics/http/shortcuts/#redirect

It's shortcut method which will redirect (big surprise ;) ) user to desired view.

4rlekin
  • 748
  • 5
  • 16
  • thanks, I used `redirect('/samplesubmission')` now, because I get an error just redirecting to the index view with `redirect('index')`, but this helps already. – drmariod Dec 03 '14 at 10:19
0

You'll want to redirect the page after the sample is added. Django has redirect methods

from django.http import HttpResponseRedirect
HttpResponseRedirect("/path/to/redirect")

This question has some more details Django: Redirect after posting a comment

Community
  • 1
  • 1
joeButler
  • 1,643
  • 1
  • 20
  • 41