【发布时间】:2012-07-16 15:01:52
【问题描述】:
我期待POST 数据,并希望创建一个自定义字典,以便在根据发布的内容创建表单时使用。我似乎在尝试比较 POST 数据中的内容时遇到了问题。我在 Ubuntu 12.04 上使用 Django 1.4 和 Python 2.7。
假设我有一个名为return_method 的POST 字段,它将告诉我客户期望的返回方法类型。他们将发送值post 或get。现在,我想根据我得到的值创建不同的字典。
if (request.POST.get('return_method') == 'get'):
cust_dict = { 'key1' : value1,
'key2' : value2,
'key3' : value3,
}
elif (request.POST.get('return_method') == 'post'):
cust_dict = { 'key1' : value1,
'key2' : value2,
'key3' : another_value,
}
这行不通。我正在使用get 填充该字段,并且没有创建任何字典。
你会建议我做什么?
编辑:看来我的问题是我的更改没有在 Django 服务器上更新。 (必须重新启动 Apache)
【问题讨论】: