我有一个Django代码,其中我提出了一个POST
请求。 POST变量包含数据,但是在尝试从form.cleaned_data ['key']读取数据时,它将引发Key错误,指出未找到密钥。 form.is_valid()
也返回false。我只提供正确的数据,并且以前运行正常
我的代码将如下所示
views.py
def open_html(request):
form = form_main.DateForm()
if request.method == 'POST':
form = form_main.DateForm(request.POST)
#print (request.POST.get('scrap_button'))
print (form.is_valid())
if form.is_valid(): # All validation rules pass
# Process the data in form.cleaned_data
# ...
#enter_time=form.cleaned_data['date']
#enter_mail_id=form.cleaned_data['mail_id']
#enter_timezone=form.cleaned_data['time_zone']
print (form.cleaned_data)
enter_mail_id = form.cleaned_data['mail_id']
enter_date = form.cleaned_data['date']
html
<form method="post">
<label >Mail ID:</label>
{% csrf_token %}
{{ form.mail_id}}
<br></br>
<div id="myOutput"></div>
<label >When to send mail?</label>
{% csrf_token %}
{{ form.date }}
<script>
$(function () {
$("#id_date").datetimepicker({
format: 'd/m/Y H:i:s',
});
});
</script>
forms.py
class DateForm(forms.Form):
mail_id=forms.CharField(max_length=100)
date=forms.DateTimeField(input_formats=['%d/%m/%Y %H:%M:%s'])