本文介绍了Django请求获取参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Django请求中,我有以下

In a Django request I have the following

 POST:<QueryDict: {u'section': [u'39'], u'MAINS': [u'137']}>

如何获取部分的值 MAINS

    if request.method == 'GET':
      qd = request.GET
    elif request.method == 'POST':
     qd = request.POST

    section_id = qd.__getitem__('section') or getlist....


推荐答案

您可以使用 [] QueryDict 对象中提取值,就像任何普通字典一样。

You can use [] to extract values from a QueryDict object like you would any ordinary dictionary.

# HTTP POST variables
request.POST['section'] # => [39]
request.POST['MAINS'] # => [137]

# HTTP GET variables
request.GET['section'] # => [39]
request.GET['MAINS'] # => [137]

# HTTP POST and HTTP GET variables (Deprecated since Django 1.7)
request.REQUEST['section'] # => [39]
request.REQUEST['MAINS'] # => [137]

这篇关于Django请求获取参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-24 15:10