📅  最后修改于: 2023-12-03 14:40:46.609000             🧑  作者: Mango
Django Tinymce is a package for Django that integrates the TinyMCE WYSIWYG editor into your website. With Tinymce, you can easily create and edit content with a visual editor that provides tools for formatting, styling, and adding multimedia content.
forms
and models
via widgets and fields.To get started with Django Tinymce, you'll need to install the package using pip:
pip install django-tinymce
Once installed, add 'tinymce'
to your INSTALLED_APPS
setting in settings.py
.
INSTALLED_APPS = [
# ...
'tinymce',
]
Next, you will need to add the Tinymce JavaScript files to your template. You can do this by including the following code snippets in the head section of your HTML file:
<script src="{% static 'tinymce/tinymce.min.js' %}"></script>
<script>
tinymce.init({
selector: 'textarea',
plugins: 'image media link',
toolbar: 'undo redo | styleselect | bold italic | alignleft aligncenter alignright alignjustify | link image media',
media_live_embeds: true,
});
</script>
Now you're all set to use the TinyMCE editor in your Django forms and models. Simply add the TinyMCEWidget
to your form or model field.
from django.db import models
from tinymce import models as tinymce_models
class Post(models.Model):
title = models.CharField(max_length=200)
content = tinymce_models.HTMLField()
Django Tinymce is a powerful tool for creating and editing content in your Django website. Its simple integration with Django's forms and models and easy customization make it a go-to choice for text editing. With this package, you can easily add a WYSIWYG editor to your Django project and provide a seamless text editing experience for your users.