简体   繁体   English

如何使用Django博客撰写复杂的帖子

[英]How to make complex post with Django blog

I'm starting Django and have been following the Djangogirls blog then I try to do my own blog. 我正在启动Django,并且一直关注Djangogirls博客,然后尝试创建自己的博客。 But I met a problem. 但是我遇到了一个问题。 A blog is used to display Posts but all posts don't have the same architecture. 博客用于显示帖子,但所有帖子的架构都不相同。 Some user want to put more picture or code sample. 一些用户想要放置更多图片或代码示例。 For example my admin page look like: 例如,我的管理页面如下所示:

我的博客上的帖子

But I suppose all the users don't want to respect this architecture. 但是我想所有用户都不想尊重这种架构。

I want my users to be able to upload images or adding code sample inside the text area. 我希望用户能够在文本区域内上传图像或添加代码示例。 But I didn't find any resources which explain me how to do it. 但是我没有找到任何资源可以解释我的操作方法。 If you could give me some inspiration source it would be great. 如果您能给我一些灵感来源,那就太好了。

I think you make be looking for a rich text editor if I understand your question correctly. 如果我正确理解您的问题,我认为您正在寻找富文本编辑器。

There are two rich text editors that are (seemingly) the most popular tinymce and ckeditor . 有两种富文本编辑器,它们(似乎)是最受欢迎的tinymceckeditor

Here's a link to a few answers that may be of use to you for the admin part: 这是指向管理员部分的一些答案的链接:

django-ckeditor-to-django-admin and django-admin-tinymce-integration django-ckeditor到django-admindjango-admin-tinymce-integration

Both of which can turn your text area into rich text editors with the ability to insert code, images, even math etcetera. 两者都可以将您的文本区域变成具有插入代码,图像甚至数学等功能的富文本编辑器。

You stated in your question: 您在问题中表示:

I want my users to be able to upload images or adding code sample inside the text area. 我希望用户能够在文本区域内上传图像或添加代码示例。

Which seems to fit the above options (or another editor). 似乎适合上述选项(或其他编辑器)。

A lightweight option would be to use Markdown instead of a raw text field. 一个轻量级的选择是使用Markdown而不是原始文本字段。

This project : https://github.com/jamesturk/django-markupfield provides a field that you can choose to parse with Markdown or other parsers. 这个项目: https : //github.com/jamesturk/django-markupfield提供了一个字段,您可以选择使用Markdown或其他解析器进行解析。 This way, you can add code samples (with ``` , like in StackOverflow). 这样,您可以添加代码示例(如StackOverflow中的``` )。

Note : the code blocks aren't colored. 注意:代码块没有颜色。

You can also include images with ![my alt text](http://example.com/image.png) , though you have to upload them somewhere on the internet. 您还可以在图像中添加![my alt text](http://example.com/image.png) ,尽管您必须将其上传到Internet上的某个位置。

For uploading images directly through the Django admin page, you may use an ImageField 要直接通过Django管理页面上传图像,可以使用ImageField

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM