def my_view(request, my_id): myitem = item.objects.get(pk=item_id) context = {'myitem': item} #this send post request button named mybutton 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)
above code. if request.post
print, has value ok in dictionary. , yet, python doesn't execute if clause.
output of request.post
:
<querydict: {u'submit': [u'ok'], u'csrfmiddlewaretoken': [u'#####']}>
afaik, request.post
has dictionary structure; has key , value. assuming request.post
has {'key': 'ok'}
, conditional statement appropriate if
if request.post['key'] == 'ok':
or better
if request.post.get('key') == 'ok':
because request.post.get
gives none
if has no such key.
Comments
Post a Comment