Answer the question
In order to leave comments, you need to log in
How to pass django variable to form action attribute?
There is a form, it has an action attribute
. At the moment, the entry is as follows:
action = "{{ page }}" It is
necessary that, under different conditions, the form is transferred to different pages
But it doesn’t work, the page does not load and gives an error that the variable is not valid, although it has been transferred
. Why might this occur?
Answer the question
In order to leave comments, you need to log in
There are two ways to put some url in the action :
1. (easier in this case) Determine this URL from the view side (taking into account the conventions) and put it in the template context (as you did). In the template, it can be used directly without constructions of the form (like yours):
that is, like this (it will be correct):
2. Take into account these conventions inside the template itself using tags and constructions, defining the variable with the desired URL and as in the first option put it in the action attribute .
I suggest you read this :)
<form action="{% url '{{ page }}' %}"><form>
<form action="{{ page }}"><form>
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question