将项目选择从templato django中的表单控件发送到视图

时间:2019-05-31 16:50:21

标签: python django django-templates

我正在从视图到模板发送一个值列表,范围为1到42,供用户选择要返回视图的值,我可以使用它,但返回键错误,该如何解决?

视图中的代码:

'Authorization': 'OAuth oauth_consumer_key="XXX",oauth_token="XXX",oauth_signature_method="HMAC-SHA1",oauth_timestamp="1559312415",oauth_nonce="XXX",oauth_version="1.0",oauth_signature="XXX"'

显示此错误:

def gerar_graficos(request):
    descricao = '01/02/2019 08:00'
    descricao2 = '01/02/2019 09:00'
    item_unidade = 0



    if request.method=='POST':
        descricao = request.POST['descricao']
        descricao2 = request.POST['descricao2']
        item_unidade = request.POST['item_unidade']


    unidade2 = ['1','2','3','4','5','6','7','8','9','10','11','12','13','14','15','16','17','18','19','20','21','22','23','24','25','26','27',
                '28','29','30','31','32','33','34','35','36','37','38','39','40','41','42']

对此视图进行编辑,将返回列表中的第一个值:

MultiValueDictKeyError at /polls/

模板代码:

def gerar_graficos(request):
    descricao = '01/02/2019 08:00'
    descricao2 = '01/02/2019 09:00'
    item_unidade = 0

    if 'is_private' in request.POST:
        item_unidade = request.POST['item_unidade']
    else:
        is_private = False


    if request.method=='POST':
        descricao = request.POST['descricao']
        descricao2 = request.POST['descricao2']


    unidade2 = ['1','2','3','4','5','6','7','8','9','10','11','12','13','14','15','16','17','18','19','20','21','22','23','24','25','26','27',
                '28','29','30','31','32','33','34','35','36','37','38','39','40','41','42']

0 个答案:

没有答案