评论表单显示不正确

问题描述

我正在对这个视频的 django 发表评论

https://www.youtube.com/watch?v=bmFkND-scpy

当视频中间的作者展示他所做的事情时,他展示了这个(应该是这样) enter image description here

但由于某种原因,结果是这样的 enter image description here

models.py

中的类注释
    class Comment(models.Model):
        post = models.ForeignKey(Post,related_name="comments",on_delete=models.CASCADE)
        name = models.CharField(max_length=255,default="Some String")
        body = models.TextField(max_length=255,null=True,blank=True)
        date_added = models.DateTimeField(auto_Now_add=True)
    
        def __str__(self):
            return '%s - %s' % (self.post.title,self.name)

forms.py

from django.forms import ModelForm

from .models import Comment


class CommentForm(ModelForm):
    class Meta:
        model = Comment
        fields = ['name','body']

views.py

中的定义细节
def detail(request,slug):
    post = Post.objects.get(slug=slug)
    form = CommentForm()
    context = {
        'post': post,'form': form
    }

    return render(request,'myblog/templates/post_detail.html',context)
 

post_detail.py

{% extends 'base.html' %}

{% block content %}
    <div class="post-entry">
        <h2>{{ post.title }}</h2>
        <p>{{ post.body }}</p>
    </div>

    <p><a href="{% url 'post_edit' post.pk %}">+ Edit Blog Post</a></p>
    <p><a href="{% url 'post_delete' post.pk %}">+ Delete Blog Post</a></p>
    <img src="{{ post.header_image.url|default_if_none:'#' }}">


    {{ post.body|urlize }}


    {% for comm in post.commentpost_set.all%}
        {{ comm.user }} <br>
        {{ comm.text }} <br><br>
    {% endfor %}

    <article class="content">

        <br><hr>
        <h2>Add a comment</h2>

        <form method="post" action=".">
            {% csrf_token %}

            {{ form.as_table }}

            <input type="submit" value="Submit">
        </form>
    </article>

{% endblock content %}

如果有必要,告诉我,我会完全扔掉文件,我只是不想用大量代码阻塞问题 非常感谢您的帮助!

解决方法

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

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

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