With rich text editor, editors of the site can write the same as using offfice a beautiful, WYSIWYG page. Here to tinymce, for example, to use other rich text editor is similar.
In a virtual environment installation package.
pip install django-tinymce==2.6.0
After installation, can be used in the management of Admin, custom form may be used.
Examples
1) was added to INSTALLED_APPS editor application in the main settings.py.
INSTALLED_APPS = ( ... 'tinymce', )
2) adding the editor disposed in the main settings.py.
TINYMCE_DEFAULT_CONFIG = { 'theme': 'advanced', 'width': 600, 'height': 400, }
3) In the configuration editor url t urls.py in the main.
urlpatterns = [ ... url(r'^tinymce/', include('tinymce.urls')), ]
Next comes the Admin page, a custom form page use.
Use the Admin in
1) In the goods / models.py, the attribute of the model is defined as HTMLField () type.
from django.db import models from tinymce.models import HTMLField class GoodsInfo(models.Model): gcontent=HTMLField()
2) generate the migration file.
python manage.py makemigrations
3) perform the migration.
python manage.py migrate
4) is not defined in the present example other model classes, but these database tables are prompted to remove, no input after the transport, represents not deleted because other examples need to use these tables.
5) the migration is complete, the new terminal opened, connected mysql, test2 database used, see table below:
6) found no table GoodsInfo, the solution is to delete the data on the migration table booktest applications.
delete from django_migrations where app='booktest';
7) perform the migration again.
python manage.py migrate
The successful completion of the migration, remember not to delete the no.
8) registered in the model class GoodsInfo booktest / admin.py in
from django.contrib import admin from booktest.models import * class GoodsInfoAdmin(admin.ModelAdmin): list_display = ['id'] admin.site.register(GoodsInfo,GoodsInfoAdmin)
9) to run the server, enter the admin back office, click GoodsInfo added, the following picture
After saving edits in the editor.