0

我正在使用 django-ckeditor 让用户在我网站的网页上输入富文本。我网站上的每个网页都代表一个具有唯一 ID 的文档。

例如,两个单独的文档将有两个带有 URL 的网页,例如 -

example.com/documents/doc1 and example.com/documents/doc2

这两个网页中的每一个都有多个 CKEDITOR。我希望当用户通过网页上的 CKEDITOR 上传图像时 - example.com/documents/doc1 应该转到单独的目录

/media/uploads/doc1/ 

并且通过网页 example.com/documents/doc2 上的 CKEDITORs 上传的图像应该转到一个单独的目录 -

/media/uploads/doc2/

现在问题就出现在这里了。在django-ckeditor模块的views.py中的上传视图方法中——

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)

它将文件名和 request.user 作为参数并将文件存储在用户特定的文件夹中。如何将 docid 从我的 url 传递到 post 请求,以便我可以使用 docid 将图像存储在以文档为中心的文件夹中?

我希望我的观点得到理解。如果需要更多信息,请在评论中告诉我,我会添加这些信息。谢谢

4

1 回答 1

0

在 config.filebrowserUploadUrl 中添加:

config.filebrowserUploadUrl = "/upload.php?docid=" + docid;
于 2015-07-05T10:38:38.043 回答