Reputation: 405
I am new to Django and followed djangogirls.com tutorial that makes a blog. In the model of a (blog) post there is a TextField
that contains a post's text. However, I am trying to make it so that I can put a variable number of pictures within that text, and at any position within it.
I wrote HTML
into a blog's text and used template tags to turn off auto-escaping. This allowed me to include images wherever I wanted, but I want to know if there is a better way to implement this? Even if someone can point me in the right direction, it would be greatly appreciated.
I'm happy to post code, I just didn't know what code would be helpful.
Upvotes: 1
Views: 206
Reputation: 13047
You can use some rich text editor for that likewyswig
or ckeditor
.
Here I am using ckeditor
First install ckeditor
pip install django-ckeditor
Then,
project settings.py
INSTALLED_APPS = [
. . . .
'ckeditor',
'ckeditor_uploader',
. . . .
]
CKEDITOR_JQUERY_URL = '//code.jquery.com/jquery-3.1.1.min.js'
CKEDITOR_UPLOAD_PATH = 'uploads/'
CKEDITOR_CONFIGS = {
'default': {
'toolbar': 'full',
},
}
project urls.py add
url(r'^ckeditor/', include('ckeditor_uploader.urls')),
app models.py
from ckeditor_uploader.fields import RichTextUploadingField
text = RichTextUploadingField(null=True, blank=True)
Upvotes: 1