gpt4 book ai didi

python - Django View 中的模板语法错误

转载 作者:行者123 更新时间:2023-12-01 00:14:00 25 4
gpt4 key购买 nike

我在我的项目中使用民意调查应用程序。投票应用程序上的网址

app_name = 'polls'
urlpatterns = [
path('', views.index, name='index'),
path('<int:question_id>/', views.results, name='results'),
path('<int:question_id>/results/', views.detail, name='detail'),
path('<int:question_id>/vote/', views.vote, name='vote')
]

在详细模板文件中,我创建了一个表单,当我单击提交按钮时,我想要转到投票页面。所以我像这样制作表单元素

<form action="{% url polls:vote question.id %}" method="post">
{$ csrf_token %}
{% for choice in question.choice_set.all %}
<input type="radio" name="choice" id="choice{{ forloop.counter }}" value="{{ choice.id }}">
<label for="choice{{ forloop.counter }}" >{{ choice.choice_text }}</label>
{% endfor %}
<input type="submit" value="Vote">
</form>

但是当我构建项目时,我可以在这种形式中看到模板渲染错误期间的错误。错误是:

Could not parse the remainder: ':vote' from 'polls:vote'

请帮我检查一下

最佳答案

在此更改

<form action="{% url 'polls:vote' question.id %}" method="post">

请参阅docs了解更多信息

关于python - Django View 中的模板语法错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59445357/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com