[Answered ]-Django form redirect

1👍

Ok, so in your .html file, you should have an action= in your form, which sort of looks like that regular expression. At the very least it should look something similar to:

action="/user/{{ object.id }}/"

object.id would be replaced with whatever object you passed to the html file in your view.

1👍

The url template tag allows you to save some repetition here. It also prevents you from breaking the form if you change urls.py. If your urlpattern looks like this:

(r'^user/(?P<id>\d+)/$', 'user.views.detail')

Then you could use the template tag like this:

<form action="{% url user.views.detail object.id %}">

Leave a comment