I
I
IIITRIX2019-05-20 10:01:15
Django
IIITRIX, 2019-05-20 10:01:15

Why the wrong way?

I'm uploading an image.
When sending I get the way

http://localhost:8000/m/Users/ckatala/Desktop/site/backend/media_root/editor_images/139.jpg

The image is not displayed but it loaded where it should!
And if you make a path
http://localhost:8000/m/editor_images/139.jpg
Everything is displayed perfectly!
This problem is only on macbook. On Windows, it works with two such paths!
I do not understand what the problem is; Here is the image upload code
def uploadFile(request):
    form = ImageForm(request.POST, request.FILES)

    if form.is_valid():
        file_ = form.cleaned_data['image']
        file_name, extension = os.path.splitext(file_.name)
        safe_name = '{0}{1}'.format(slugify(file_name), extension)
        name = os.path.join(settings.EDITOR_IMAGE_UPLOAD_PATH, safe_name)

        data = dict()
        data['path'] = default_storage.save(name, file_)
        data['url'] = request.build_absolute_uri(default_storage.url(data['path']))

        res = {
            "success": 1,
            "file": {
                "url": data['url']
            }
        }

    else:
        res = {
            "success": 0,
            "file": {
                "url": None
            }
        }

    return JsonResponse(res)

MEDIA_URL = '/m/'
EDITOR_IMAGE_UPLOAD_PATH = os.path.join(MEDIA_ROOT, 'editor_images')
MEDIA_ROOT = os.path.join(BASE_DIR, 'media_root')

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
IIITRIX, 2019-05-20
@IIITRIX

Problem solved
here
MEDIA_ROOT = os.path.join('media_root')

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question