S
S
SHADRIN2020-07-05 21:53:52
Django
SHADRIN, 2020-07-05 21:53:52

How to pass a variable from a form to a view?

Need to pass a variable from form

{% for i in good %}
  <p>{{  i.results  }}</p>
    	<form action="/comment/" method="post" enctype="multipart/form-data">{% csrf_token %}
      <label for="com">Комментарий:</label>
      <input type="text" name="com" value="">
      <input type='hidden' value="{{  i.id }}" name="index"> 
      <input type="submit" value="Ок">

    </form>

{% endfor %}
  <a href="/" class="btn btn-outline-secondary">Перейти на главную</a>
{% endif %}
{% endblock %}


The variable itself, i.id, is written in input hidden (it was advised) I can’t pass it, what can I do?
forms.py
class Comment(forms.Form):
    com = forms.CharField(label='Комментарий:', max_length=100)

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question