简体   繁体   中英

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. 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 .

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

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.

This project : https://github.com/jamesturk/django-markupfield provides a field that you can choose to parse with Markdown or other parsers. This way, you can add code samples (with ``` , like in 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.

For uploading images directly through the Django admin page, you may use an ImageField

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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