Is it ok to put html code in Django TextField? - python

Is it good to put html code in a Django TextField that will be used in a blog app?

It's all right you use any HTML in django textfield, for example, if you are using TinyMCE, this kind of list can be used very easily

Use this to put html code in text field. ckeditor is great html editor with many plugin also it has django library with many customize functionality
https://github.com/django-ckeditor/django-ckeditor

Related

TinyMCE Django Framework

I am using the TinyMCE editor for the admin part of my website. The editor seems like it is installed correctly but after saving a post and displaying it on the main page it shows the raw html instead of rendering it.
More specifically it shows
If it helps I used HTMLField in the model
when you want to display html stored in a model you need to mark it as safe (if it is of course) for it to bypass the XSS protection
see https://docs.djangoproject.com/en/1.10/ref/templates/builtins/#safe
Marks a string as not requiring further HTML escaping prior to output.
When autoescaping is off, this filter has no effect.
example for your template
{{ model.attribute|safe}}

Can I debug django to display which template it is rendering?

I use django for a large project that is new for me and has many templates. Now I was asked to edit a template that I can display in the browser but I don't know where the template is. Is there a way to make django write out which template it is rendering (and possibly which python classes are used)? Similar to what happens at an error where there is lots of information about what is used.
yes definitely, you can use django debug toolbar for this !

How to allow users to build their own flatpages in Django?

I have an app that allows users (admins actually) to add html to a model. Then I serve that html on some page to other users (nonadmins). I would like to allow the admins to create arbitrary html on these pages, including adding images. I don't want the admins to have to jump through hoops to get their content into this html field. Suppose a user has some images on their local machine that they want to go into this html field they are creating. I want it to be super brain-dead easy for them to get those images in there.
Right now I just have a model with an html field and I provide a WYSIWYG editor . On a page that users can see, I just load that model.html (filter it as safe) and display. But if the admin user wants to add an image, they still have to figure out hosting and linking in their html document.
Is there a way to use Django flatpages + static to achieve this? Or some kind of app that provides a wordpress-like editor inside Django?
Honestly I would recommend just installing Mezzanine. It does exactly what you want and is the most lightweight, simple and Wordpress like of the Django CMSs. It integrates TinyMCE and Django filebrowser like you want and you can throw away the bits you don't want. This is almost definitely the quickest way to do what you want.

generating httptemplate (html) using python code

I have used python so far only for simple applications. I want to create a html file using python code which I can use on web server. How can I create this template using Django?
you'll need an intro, take a look at this post http://elleestcrimi.me/2012/03/15/introduction-django-guestbook-application/
it walks you through creating a simple django app.
if there's something you can't understand there, you can comment on the blog post,
the owner is very helpful

Standard Django way for letting users edit rich content

I have a Django website in which I want site administrators to be able to edit rich content.
Suppose we're talking about an organizational info page, which might include some pictures, and some links, where the page is not as structured as a news page (which updates with news pieces every few days), but still needs the ability to be easily edited by site admins which do not necessarily want to mess with HTML (or rather, I do not want them to).
So where do I put this dynamic content? On the database? In which format? How do I make it accesible in the django default admin?
Use one of the existing rich-text editors
The lightest weight would be to use something at the js level like DojoEditor:
http://code.djangoproject.com/wiki/AddDojoEditor
See also this thread:
Replace textarea with rich text editor in Django Admin?
For what you're describing I'd use flatpages, which is a django app that lets users create and edit pages in the admin panel.
As for formatting, I'd use TinyMCE. Integrating it is pretty easy, here is a walkthrough (do steps 1 and 2 and jump to the bottom, "Using TinyMCE with flatpages (newforms)")

Categories