def my_view(request, my_id):
myItem = Item.objects.get(pk=item_id)
context = {'myitem': my item}
#This is where I send a POST request from a button named myButton with a value="OK".
if request.method == "POST":
if 'OK' in request.POST:
return render(request, 'url1', context)`enter code here`
else:
return render(request, 'url2', context)
以上是我的代码。如果我打印request.POST
,它实际上在字典中的值为OK。然而,Python不执行if子句。
request.POST
的输出是:
<QueryDict: {u'submit': [u'OK'], u'csrfmiddlewaretoken': [u'#####']}>
答案 0 :(得分:1)
AFAIK,request.POST
有字典结构;它具有关键和价值。假设request.POST
具有{'key': 'OK'}
,则条件语句适用于
if request.POST['key'] == 'OK':
或者这会更好
if request.POST.get('key') == 'OK':
因为如果request.POST.get
没有这样的密钥,None
会给Crashlytics was applied to a project without an Android plugin. Please make sure the Crashlytics plugin is applied after the appropriate Android plugin for your project.
。