Answer the question
In order to leave comments, you need to log in
Why doesn't POST work in Django?
There is a form:
<form class="form-horizontal" role="form" action="{% url 'trucking:add_order' %}" method="post">
{% csrf_token %}
<div class="form-group">
<label for="sending_office" class="col-sm-3 control-label">Пункт отправления</label>
<div class="col-sm-6">
<input type="text" class="form-control" id="sending_office" placeholder="Пункт отправления" />
</div>
</div>
<div class="form-group">
<label for="destination_office" class="col-sm-3 control-label">Пункт назначения</label>
<div class="col-sm-6">
<input type="text" class="form-control" id="destination_office" placeholder="Пункт назначения" />
</div>
</div>
<p class="col-sm-3"></p>
<a href="/trucking/offices" target='blank'>Список пунктов приема/выдачи</a>
<div class="form-group">
<label for="services" class="col-sm-3 control-label">Дополнительный услуги:</label>
<div class="col-sm-6">
<select multiple class="col-sm-6 form-control" id="services">
{% for option in service_list %}
<option>{{ option.name }} - {{ option.price }} руб.</option>
{% endfor %}
</select>
</div>
</div>
<div class="form-group">
<div class="col-sm-offset-3 col-sm-10">
<input type="submit" class="btn btn-default" value="Заказать" />
</div>
</div>
</form>
def add_order(request):
sending_office = request.POST['sending_office']
Environment:
Request Method: POST
Request URL: http://localhost:8000/trucking/add_order/
Django Version: 1.6
Python Version: 3.3.2
Installed Applications:
('django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'trucking')
Installed Middleware:
('django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware')
Traceback:
File "/usr/local/lib/python3.3/dist-packages/django/core/handlers/base.py" in get_response
114. response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "/home/rokker/yadisk/workspace/trucking_industry/trucking/views.py" in add_order
27. sending_office = request.POST['sending_office']
File "/usr/local/lib/python3.3/dist-packages/django/utils/datastructures.py" in __getitem__
301. raise MultiValueDictKeyError(repr(key))
Exception Type: MultiValueDictKeyError at /trucking/add_order/
Exception Value: "'sending_office'"
Answer the question
In order to leave comments, you need to log in
Well, my eyes are blurry. Sacredly believed that only id is needed. Thank you!
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question