1
Good night!
I created a view where I recover the sellers and created a variable (id_seller) to receive the selected seller on the screen. html is being created correctly, but the variable in the view does not receive value in the POST:
View:
def novo_orcamento(request):
vendedores = Vendedor.objects.order_by('nome')
id_vendedor = 0
if request.method == 'POST':
import pdb
pdb.set_trace()
context = {'vendedores':vendedores, 'id_vendedor':id_vendedor}
return render(request, 'appOrcamento/novo_orcamento.html', context)
Html
{% block content %}
<form action="{% url 'appOrcamento:novo_orcamento' %}" method="POST">
{% csrf_token %}
<div class="form-group">
<legend class="lead">PRODUTOS</legend>
<select name=id_vendedor class="form-control">
{% for vendedor in vendedores %}
<option value="{{vendedor.codigo_id}}">{{vendedor.nome}}</option>
{% endfor %}
</select>
<button name='submit' class="btn btn-primary">Salvar</button>
</div>
</form>
{% endblock content %}
How do I recover the selected seller in the view?
Marlysson, thank you for your help. It worked perfectly, I will end my doubt with your reply.
– Seixas