我正在使用django-ckeditor让用户在我网站的网页上输入富文本。我网站上的每个网页都代表一个具有唯一ID的文档。
对于前两个单独的文档,将有两个带有URL的网页,例如 -
example.com/documents/doc1 and example.com/documents/doc2
这两个网页中的每一个都有多个CKEDITOR。我希望当用户通过网页上的CKEDITOR上传图片时,example.com / docs / doc1应该转到一个单独的目录
/media/uploads/doc1/
通过网页example.com/documents/doc2上的CKEDITOR上传的图片应该转到一个单独的目录 -
/media/uploads/doc2/
现在问题就出现了。在django-ckeditor模块的views.py中的upload视图方法中 -
def post(self, request, **kwargs):
"""
Uploads a file and send back its URL to CKEditor.
"""
# Get the uploaded file from request.
upload = request.FILES['upload']
#Verify that file is a valid image
backend = image_processing.get_backend()
try:
backend.image_verify(upload)
except utils.NotAnImageException:
return HttpResponse("""
<script type='text/javascript'>
alert('Invalid image')
window.parent.CKEDITOR.tools.callFunction({0});
</script>""".format(request.GET['CKEditorFuncNum']))
# Open output file in which to store upload.
upload_filename = get_upload_filename(upload.name, request.user)
saved_path = default_storage.save(upload_filename, upload)
if backend.should_create_thumbnail(saved_path):
backend.create_thumbnail(saved_path)
url = utils.get_media_url(saved_path)
# Respond with Javascript sending ckeditor upload url.
return HttpResponse("""
<script type='text/javascript'>
window.parent.CKEDITOR.tools.callFunction({0}, '{1}');
</script>""".format(request.GET['CKEditorFuncNum'], url))
upload_filename定义为 get_upload_filename(upload.name,request.user)
它将filename和request.user作为参数并将文件存储在用户特定的文件夹中。如何将docid从我的url传递给post请求,以便我可以使用docid将图像存储在以文档为中心的文件夹中?< / p>
我希望我的观点能被理解。如果需要更多信息,请在评论中告诉我,我会补充一下。感谢
答案 0 :(得分:0)
将其添加到config.filebrowserUploadUrl:
中config.filebrowserUploadUrl = "/upload.php?docid=" + docid;