Django:循环调用template + view

问题描述

| 我正在进行多页民意调查。我有一个数据库,该数据库有一个称为页面的列,每个页面有4个问题。用户在页面上回答所有问题后,单击“下一步”并转到下一页。 我可以查询数据库以找出需要生成的页面数,但是我不确定如何循环模板渲染过程。 这是我的代码: 用户输入:
def index(request):
latest_poll_list = Poll.objects.filter(page=1)
t = loader.get_template(\'index.html\')
c = Context({
    \'latest_poll_list\': latest_poll_list,})
return HttpResponse(t.render(c))
...将生成此模板:
    <ul>

<form action=\"/first/vote/\" method=\"post\">
{% csrf_token %}
{% for poll in latest_poll_list %}
    <li>{{ poll.question }}</li>
        {% for choice in poll.choice_set.all %}
            <input type=\"radio\" name=\"choice{{ poll.id }}\" id=\"{{poll.id}}choice{{ forloop.counter }}\" value=\"{{ choice.id }}\" />
            <label for=\"choice{{ forloop.counter }}\">{{ choice.choice }}</label><br />
        {% endfor %}
{% endfor %}
    <input type=\"submit\" value=\"Vote\" />
</form>

</ul>
...然后在这里处理用户的选择:
def vote(request):
intra_page_key = request.POST[\'choice1\']+\',\'+request.POST[\'choice2\']+\',\'+request.POST[\'choice3\']
request.session[\'p1\'] = intra_page_key
return HttpResponse(request.session[\'p1\'])
如何为我的民意调查第2页重复此顺序?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)