[英]if there are instances of method that user created display them else display a string Django
[英]how to display questions to user and compare them using "if" "else" statements expert system django?
我已将规则以问题的形式存储在数据库中,并希望由用户提出问题,然后得出结果。 我希望问题以是或否选项显示在用户屏幕上,并根据选择提出更多问题。 我无法找到一个解决方案,我应该如何比较前端和后端(django)的用户输入到目前为止我已经尝试过
视图.py
def fetch_rules(request):
if request.method=='POST':
issueid=request.POST['issueid']
rules=Rules.objects.all().filter(parentissue=issueid)
return render(request,"questions.html",{"rules":rules})
else:
return HttpResponse("Not found")
模板
{% extends 'base.html' %}
{% block content%}
<div class="questionwrapper">
{% for rul in rules %}
<div class="question">
<h1>{{rul.question}}</h1>
</div>
<div class="solution">
<p>{{rul.solution}}</p>
</div>
<p style="text-align: center;font-weight: bold;">Your issue solved?</p>
<div class="question_btns">
<a id="yes_q" >Yes</a>
<a id="no_q" >No</a>
</div>
{%endfor%}
</div>
{% endblock %}[![My template][1]][1]
当前模板显示所有问题,但我想一次显示一次,然后根据用户的选择一个接一个地显示。
如果要动态添加内容,必须使用前端技术。 您所要做的就是使用 CSS display:none
隐藏问题,然后在按钮上设置 onclick 事件,一个简单的 JS 脚本将更改特定子display:nth-child(n):inline-block
您也可以使用对象 id 做一些类似的事情,例如:
<div class="question" data-id={{rul.question.id}}>
<h1>{{rul.question}}</h1>
</div>
现在您可以使用 data-id 和 JavaScript 对对象进行排序或显示
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.