Python Django教程添加/删除投票问题
我正在学习Django创建应用程序教程,可在以下网址找到: 我已经按照链接的指示完成了教程,我有一个接受民意调查的网站。它运行良好,但是我希望通过允许用户在投票页面上添加和删除问题,而不必通过管理页面,从而使投票对用户更具交互性。我该怎么办 谢谢大家! 这是我的index.html:Python Django教程添加/删除投票问题,python,html,django,Python,Html,Django,我正在学习Django创建应用程序教程,可在以下网址找到: 我已经按照链接的指示完成了教程,我有一个接受民意调查的网站。它运行良好,但是我希望通过允许用户在投票页面上添加和删除问题,而不必通过管理页面,从而使投票对用户更具交互性。我该怎么办 谢谢大家! 这是我的index.html: {% load static %} {% if latest_question_list %} <ul> {% for question in latest_question_list
{% load static %}
{% if latest_question_list %}
<ul>
{% for question in latest_question_list %}
<li><a href="/polls/{{ question.id }}/">{{ question.question_text }}</a></li>
{% endfor %}
</ul>
{% else %}
<p>No polls are available.</p>
{% endif %}
<link rel="stylesheet" type="text/css" href="{% static 'polls/style.css' %}">
<h1>{{ question.question_text }}</h1>
<ul>
{% for choice in question.choice_set.all %}
<li><a href="{% url 'polls:detail' question.id %}">{{ question.question_text }}</a></li>
{% endfor %}
</ul>
{%load static%}
{%if最新问题列表%}
{最新问题列表%中的问题%
{%endfor%}
{%else%}
没有投票
{%endif%}
{{question.question_text}
{问题中的选项为%choice\u set.all%}
{%endfor%}
这是我的models.py文件,可以在我的轮询应用程序的templates目录中找到:
import datetime
from django.db import models
from django.utils import timezone
class Question(models.Model):
question_text = models.CharField(max_length=200)
pub_date = models.DateTimeField('date published')
def __str__(self):
return self.question_text
def was_published_recently(self):
now = timezone.now()
return now - datetime.timedelta(days=1) <= self.pub_date <= now
was_published_recently.admin_order_field = 'pub_date'
was_published_recently.boolean = True
was_published_recently.short_description = 'Published recently?'
class Choice(models.Model):
question = models.ForeignKey(Question,
on_delete=models.CASCADE)
choice_text = models.CharField(max_length=200)
votes = models.IntegerField(default=0)
def __str__(self):
return self.choice_text
导入日期时间
从django.db导入模型
从django.utils导入时区
课堂提问(models.Model):
问题文本=models.CharField(最大长度=200)
发布日期=models.datetime字段(“发布日期”)
定义(自我):
返回self.question\u文本
def最近发布(自我):
now=时区。now()
return now-datetime.timedelta(days=1)您必须添加一些代码和详细信息。