views.py 文件源码

python
阅读 23 收藏 0 点赞 0 评论 0

项目:Intranet 作者: mituSkillologies-Interns 项目源码 文件源码
def vote(request, question_id):
    question = get_object_or_404(Question,pk = question_id)
    try:
        selected_choice = question.choice_set.get(pk = request.POST['choice'])
    except (KeyError, Choice.DoesNotExists):
        return render(request, 'polls/detail.html',{
            'question': question,
            'error_message' : "You didn't select a choice.",
        })
    else:
        selected_choice.votes += 1
        selected_choice.save()
        return HttpResponseRedirect(reverse('polls:results', args = (question.id)))
    #return HttpResponse("You're voting on question %s." % question_id)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号