I’m new with Django and I’m creating a sport app.
I allow users to create a match (choosing their team and their style), and I want to redirect them to a specific page (the one of their match) after they create it with a form.
Here is my form:
{% if user.is_authenticated %}
<form method="post">
{% csrf_token %}
<input type="radio" name="supporting" value={{teamA.id}} /> {{teamA}}
<input type="radio" name="supporting" value="" /> Neutre
<input type="radio" name="supporting" value={{teamB.id}} /> {{teamB}}
<hr>
<input type="radio" name="style" value="1" /> Funny
<input type="radio" name="style" value="3" /> Mixed
<input type="radio" name="style" value="2" /> Technical
</br></br>
<input type="submit" value="Create your match!" />
</form>
{% else %}
I’m able to redirect a user when he chooses a match that is already created. But I don’t know how to redirect to a specific page with the same button that is used to create the match.
Thank you for your help
In your view, using
HttpResponseRedirect()to appropriate url after processing a form you can redirect to new page. Refer doc: Using a form in a viewUpdate : to redirect to match page with id
If your url for match detail page is something like this:
Then you can redirect using this