Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/310.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python html中的if条件_Python_Html_Css_If Statement - Fatal编程技术网

Python html中的if条件

Python html中的if条件,python,html,css,if-statement,Python,Html,Css,If Statement,我是django的新手。在这里,我尝试使用django做一个民意测验应用程序。 我想显示“您输入的正确信息” if selected_choice='Yellow' 这是我的密码 def results(request, question_id): question = get_object_or_404(Question, pk=question_id) try: selected_choice = question.choice_set.get(pk=req

我是django的新手。在这里,我尝试使用
django
做一个民意测验应用程序。 我想显示“您输入的正确信息”

if selected_choice='Yellow'
这是我的密码

def results(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.DoesNotExist):
    # Redisplay the question voting form.
        return render(request, 'polls/detail.html', {
        'question': question,
        'error_message': "You didn't select a choice.",
    })
    else:

        selected_choice.votes += 1
        selected_choice.save()
        context_dict={}
        context_dict['selected_choice']=selected_choice
        context_dict['question']=question

        return render(request, 'polls/result.html', context_dict)
html文件

<h1>{{ question.question_text }}</h1>
{% if selected_choice  %}
    {% if 'Yellow' %}

    <p> you entered correct </p>
    {% endif %}

{% endif %}


<ul>
{% for choice in question.choice_set.all %}
<li>{{ choice.choice_text }} -- {{ choice.votes }} vote{{     choice.votes|pluralize }}</li>
{% endfor %}
</ul>
{{question.question_text}
{%if selected_choice%}
{%if'黄色'%}
你输入的是正确的

{%endif%} {%endif%}
    {问题中的选项为%choice\u set.all%}
  • {{choice.choice{u text}}--{{choice.voces}}投票{{choice.voces}复数化}
  • {%endfor%}

如果所选内容是字符串值:

“==”前后的空白很重要;这是经常错过的

   {% if selected_choice == 'Yellow' %}
    <p> you entered correct </p>
   {% endif %}
{%if selected\u choice=='Yellow%}
你输入的是正确的

{%endif%}
您也可以尝试:

   {% ifequal selected_choice 'Yellow' %} 
    <p> you entered correct </p>
   {% endifequal %}
{%ifequal selected_choice'黄色'%}
你输入的是正确的

{%endifequal%}
如果所选内容是字符串值:

“==”前后的空白很重要;这是经常错过的

   {% if selected_choice == 'Yellow' %}
    <p> you entered correct </p>
   {% endif %}
{%if selected\u choice=='Yellow%}
你输入的是正确的

{%endif%}
您也可以尝试:

   {% ifequal selected_choice 'Yellow' %} 
    <p> you entered correct </p>
   {% endifequal %}
{%ifequal selected_choice'黄色'%}
你输入的是正确的

{%endifequal%}
html文件中的以下if条件无法正常工作。html中的这个if条件最好称为模板:)为什么将
if
语句拆分为两个语句?
{%if selected\u choice=='Yellow%}
解决了问题吗?@rkatkam有下面的正确答案-请参阅文档-html文件中的以下if条件工作不正常。html中的这个if条件最好称为模板:)为什么将
if
语句拆分为两个语句?
{%if selected\u choice==“Yellow”%}
是否解决了问题?@rkatkam有下面的正确答案-请参阅文档-什么是“selected\u choice”?它是物体吗?我这样认为是因为您对其调用了save()方法。您是否将“Yellow”值存储为其字段之一?在这种情况下,您需要声明类似{%if selected_choice.name==“Yellow”%}。我知道了。我将类型(selected_choice)转换为string。这会产生确切的答案什么是“selected_choice”?它是物体吗?我这样认为是因为您对其调用了save()方法。您是否将“Yellow”值存储为其字段之一?在这种情况下,您需要声明类似{%if selected_choice.name==“Yellow”%}。我得到了它。我将类型(selected_choice)转换为string。这将生成准确的答案