python - 有什么方法可以更改管理面板中文本字段 django 的默认文本编辑器?

标签 python django

我正在 django 上开发这个项目,我有这个模型,它有几个字符字段和一个文本字段。我想知道的是,无论如何,我可以在 django 管理面板中编辑文本字段的外观,这样我就可以编辑在该文本字段中编写的内容,就像 word press 中的文本字段一样,您可以选择将文本设为粗体或插入链接和图像。
我尝试了这个名为 grappelli 的模块,但它只是改变了我的管理面板的外观,添加了颜色和装饰性的东西。

class Heading(models.Model):
    category = models.ForeignKey(Category)
    title = models.CharField(max_length=5000)
    content = models.TextField()
    date = models.DateField(default=datetime.now())



def __str__(self):
    return self.title

最佳答案

使用ckeditor

https://github.com/django-ckeditor/django-ckeditor

在外壳上:
pip 安装 django-ckeditor

在settings.py上:
在 INSTALLED_APPS 上添加“ckeditor”

在 models.py 上:

from ckeditor.fields import RichTextField
class Heading(models.Model):
    content = RichTextField()

关于python - 有什么方法可以更改管理面板中文本字段 django 的默认文本编辑器?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34149541/

相关文章:

python - 生成所有可能组合的 numpy 数组(物种组合)

python - 如何在运行时覆盖 C 函数(如 LD_PRELOAD)?

python - 如何将 wxPython 应用程序转换为作为 headless unix 作业运行?

python - 云端代码

Django:TemplateDoesNotExist 在/

python - django 序列化外键对象

python - 升级到Ubuntu 20.04杀害 pip

python - 如何从Python请求中检索字典数据?

django - 如何根据另一个模型中的另一个字段在 django 模型中设置新字段?

python - Django - 记录唯一 ID