【发布时间】:2020-11-08 19:02:33
【问题描述】:
我希望如果用户选择 Not public 作为他的下拉选项,则帖子不会显示,如果是 Public,则会显示。
index.html 代码:
<!DOCTYPE html>
<html lang="en" dir="ltr">
<head>
<meta charset="utf-8">
<title></title>
</head>
<body>
{% for post_object in object_list %}
{% if post_object.choices == "Public" %}
<h1>{{ post_object.post_title }}</h1>
<p>{{ post_object.post_description }}</p>
{% else %}
{% endif %}
{% endfor %}
</body>
</html>
models.py 代码:
class Post(models.Model):
post_title = models.CharField("Post title", max_length=200)
post_description = models.TextField("Small description of your post")
post_summary = models.TextField("Post summary")
post_public = models.CharField(max_length=300, choices=[('Not public', 'Not public'), ('Public', 'Public')], default="Not public")
def __str__(self):
return self.post_title
我如何知道用户当前选择了什么选项?
【问题讨论】:
标签: html python-3.x django django-models django-templates