Add Markdown for django content additional
You wanna this ?
See the Content on Blog Postings model on image above, I write the command line like #, tag html <center>, <img> tag and the result is look like this :
Install the Markdown first with command :
Note !!!
Make sure you have activated the virtual environment,
Mac user : source venv/bin/activate
Windows user : venv/Scripts/activate
pip install Markdown
Okay so let’s going to my code! In this case my project name is mysite and start from models on myapp name is blog.
blog/models.py
mysite/urls.py
next configure the urls.py on your app create new file urls.py
blog/urls.py
next create class and function on your views.py file on app(blog)
blog/views.py
After 4 file configuration done, let’s migrate it into database with command:
python manage.py makemigrations
python manage.py migrate
Next step is register the model to your admin panel,
blog/admin.py
There are additional python files that must be created, I named it blog_md.py create it on blog directory.
blog/blog_md.py
I using this on PostDetail, for Detailing the content. So I give the direct file into post detail. Named it post_detail.html on your templates directory.
templates/post_detail.html
See the code on line 14, I call the content (Post models), and call the convert (the convert function you can see on the blog_md.py file), and give the safe instructions (If you not add this safe, the result on your content is showing the html tag). Done for it,
Hope this help. You can also check the full of django and markdown here
Don’t forget to visit Soedarha for other tutorial updates.