在 django-ckeditor 中上传图像时如何禁用非管理员的浏览服务器选项?
How to disable browse server option for non admin while uploading image in django-ckeditor?
我有一个关于 django 的博客,任何 public 都可以在上面 post。在 post 内容中,我使用的是 django-ckeditor RichTextUploadingField。
ckeditor中有图片浏览服务器按钮,可以让用户浏览服务器上传目录的图片,并在post中嵌入图片。
但我想限制 public 在服务器上浏览图像时 post。他们应该只能上传图片,不能浏览服务器上上传的每张图片。
这是我的models.py
class Article(models.Model):
title = models.CharField(max_length = 200)
content = RichTextUploadingField()
author = models.ForeignKey(User, on_delete= models.CASCADE, null=True)
def __str__(self):
return self.title
Forms.py
class ArticleForm(ModelForm):
class Meta:
model = Article
widgets = {
'content': RichTextUploadingField()
}
未提供删除此功能的直接设置,但 CKEDITOR_RESTRICT_BY_USER = True
可用于实现相同目的。
文档参考:
Set the CKEDITOR_RESTRICT_BY_USER
setting to True
in the project's
settings.py
file (default False
). This restricts access to uploaded
images to the uploading user
(e.g. each user only sees and uploads
their own images). Upload paths are prefixed by the string returned by
get_username
. If CKEDITOR_RESTRICT_BY_USER
is set to a string
, the
named property is used instead. Superusers can still see all images.
NOTE: This restriction is only enforced within the CKEditor media
browser.
我有一个关于 django 的博客,任何 public 都可以在上面 post。在 post 内容中,我使用的是 django-ckeditor RichTextUploadingField。
ckeditor中有图片浏览服务器按钮,可以让用户浏览服务器上传目录的图片,并在post中嵌入图片。
但我想限制 public 在服务器上浏览图像时 post。他们应该只能上传图片,不能浏览服务器上上传的每张图片。
这是我的models.py
class Article(models.Model):
title = models.CharField(max_length = 200)
content = RichTextUploadingField()
author = models.ForeignKey(User, on_delete= models.CASCADE, null=True)
def __str__(self):
return self.title
Forms.py
class ArticleForm(ModelForm):
class Meta:
model = Article
widgets = {
'content': RichTextUploadingField()
}
未提供删除此功能的直接设置,但 CKEDITOR_RESTRICT_BY_USER = True
可用于实现相同目的。
文档参考:
Set the
CKEDITOR_RESTRICT_BY_USER
setting toTrue
in the project'ssettings.py
file (defaultFalse
). This restricts access to uploaded images to theuploading user
(e.g. each user only sees and uploads their own images). Upload paths are prefixed by the string returned byget_username
. IfCKEDITOR_RESTRICT_BY_USER
is set to astring
, the named property is used instead. Superusers can still see all images. NOTE: This restriction is only enforced within the CKEditor media browser.