Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/312.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/89.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python Django博客文本格式(初学者)_Python_Html_Django_Blogs_Text Formatting - Fatal编程技术网

Python Django博客文本格式(初学者)

Python Django博客文本格式(初学者),python,html,django,blogs,text-formatting,Python,Html,Django,Blogs,Text Formatting,我只是想知道,当我在博客应用程序中从django将文本输入我的管理页面时,如何格式化文本。我有文章/博客应用程序的基本代码 在models.py中: class Article(models.Model): title = models.CharField(max_length=200) body = models.TextField() pub_date = models.DateTimeField('date published') likes = model

我只是想知道,当我在博客应用程序中从django将文本输入我的管理页面时,如何格式化文本。我有文章/博客应用程序的基本代码

在models.py中:

class Article(models.Model):
    title = models.CharField(max_length=200)
    body = models.TextField()
    pub_date = models.DateTimeField('date published')
    likes = models.IntegerField()
def __str__(self):
    return self.title
是否需要在“body”变量中添加一些内容?我试着键入类似的内容

<br>

在django管理员页面中发布文章时,在文本字段中键入文本。html文件如下所示:

<h1>{{ article.title }}</h1>
<p>{{ article.body }}</p>
{{article.title}
{{article.body}

但我输入的文本没有变化。有人能帮忙吗?我一直在寻找,也许我没有做最好的寻找工作,但我似乎找不到如何做到这一点。只是希望在写博客文章时编辑文本变得简单

提前感谢您的帮助和/或建议,非常感谢。

请尝试内置过滤器。像这样使用它:

...
<p>{{ article.body|linebreaks }}</p>
。。。
{{article.body | linebreaks}}


现在,在你的管理页面中,你可以像在你使用的任何文本编辑器中一样插入新行。

听起来你想要一个所见即所得编辑器,有很多。我以前在Django使用过TINYMCE,没有任何问题。

谢谢您的链接,我现在正在查找这些内容。虽然这可能不会立即解决我的问题,但这可能会带来更好的结果。非常感谢。