Hi Im trying to build a html with python in backen (Django 5) and I trying to take a variable from HTML to python
I found this old question and try to use that Django – pass value from html template to python function
But I stuck in views.py I dont know how set path in url patters and I follow the answear,
please can some help to figure out this
my view.py file:
urlpatterns = [
path('form_page/',views.form_name_view,name='form_page'),
path('register/',views.register,name='register'),
path('project_info/',views.project_info,name='project_info'),
path('user_login/',views.user_login,name='user_login'),
from old question Django – pass value from html template to python function
<input type="text" name="name_id" placeholder="placeholder value"/>
<input type="submit" name="value1"/>
<input type="submit" name="value2"/>
<input type="submit" name="value3"/>
In the view you can then check with:
def some_view(request):
if request.method == 'POST':
if 'value1' in request.POST:
# …
pass
elif 'value2' in request.POST:
# …
pass
elif 'value3' in request.POST:
# …
pass
You can work with a name="…" attribute on the submit <button>s:
<form method="POST" action="">
{% csrf_token %}
<input type="text" name="name_id" placeholder="placeholder value"/>
<input type="submit" name="value1"/>
<input type="submit" name="value2"/>
<input type="submit" name="value3"/>
</form>
In the view you can then check with:
def some_view(request):
if request.method == 'POST':
if 'value1' in request.POST:
# …
pass
elif 'value2' in request.POST:
# …
pass
elif 'value3' in request.POST:
# …
pass