Rich Text Field CKeditor Install
You will want your text typed in the admin section to remain formatted. By default django will just turn it all into a long string of plain text.
You should use an additional WYSIWYG module - ckeditor
PythonAnywhere Install:
Open a bash console and type pip3.6 install --user django-ckeditor
Note that you literally type “--user” not your username! Also, the pip3.6 depends on the version of python you are using.
Check the python version of your virtual environment first (not the top level bash script)
workon django18
python --version
Or go into the virtual environment by using workon django18 (or whatever you called it) and then pip install django-ckeditor
In your top-level settings.py file:
INSTALLED_APPS = (
...
'ckeditor',
)
....
STATIC_URL = '/static/'
MEDIA_URL = '/media/'
CKEDITOR_UPLOAD_PATH = "uploads/"
CKEDITOR_RESTRICT_BY_USER = True
CKEDITOR_CONFIGS = {
'default': {
'toolbar': 'Advanced',
'width': 758,
'height': 300,
},
}
Next, go to the top-level urls.py
urlpatterns = [
...
url(r'^ckeditor/', include(''ckeditor_uploader.urls')),
]
Now go into your app and open it’s models.py file so username/app/models.py
from django.db import models
from ckeditor.fields import RichTextField
class Project(models.Model):
project_code = RichTextField(verbose_name='Code',null=True,blank=True)
Making all those changes, especially adding in a new installed app, means you have to update the database. And do a static collection.
python manage.py collectstatic
python manage.py makemigrations <your-app-name>
python manage.py migrate
Finally, when using variable names in the html templates by default Django will not read the html tags generated by CKeditor. Instead it will print them. So you will see <p>my sentence</p>
To fix that make the variable names “safe”
{{project.project_code|safe}}