我想让我的博客像Facebook一样,在Facebook上创建帖子的选项与帖子列表的视图相同。你知道吗
我试图在我的ListView中包含CreateView模板,但它给了我以下错误:
Parameter "form" should contain a valid Django Form.
我也尝试在评论中使用同样的方法。这个方法行得通还是有别的方法?你知道吗
这是post_list.html
模板:
{% extends "posts/post_base.html" %}
{% load bootstrap4 %}
{% block post_content %}
<div class="col-md-6">
{% for post in post_list %}
{% include "posts/_post.html" %}
{% inclide 'posts/_create_post.html %}
{% endfor %}
</div>
{% endblock %}
这是create_post.html
模板:
{% load bootstrap4 %}
<form method="POST">
{% csrf_token %}
{% bootstrap_form form %}
<input type="submit" name="" value="comment">
</form>
我要做的只是在列表模板中包含create模板。如果这不起作用,我只想让用户在同一个页面上创建一个新的帖子,就像Facebook一样。你知道吗
在ListView中,您需要添加表单
然后你应该能够在模板中使用
相关问题 更多 >
编程相关推荐