Ask Your Question
4

How can the path for image uploads in the CKEeditor field be altered in Django?

asked 2021-08-26 11:00:00 +0000

lalupa gravatar image

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
3

answered 2021-11-30 11:00:00 +0000

ladyg gravatar image

The path for image uploads in the CKEeditor field can be altered in Django by modifying the MEDIAROOT and MEDIAURL settings in the settings.py file.

  1. Modify MEDIA_ROOT:

By default, the MEDIAROOT is set to the project's root directory. To change the MEDIAROOT to a different directory, add the absolute path of the new directory as a string to the settings.py file.

MEDIA_ROOT = '/absolute/path/to/media/'
  1. Modify MEDIA_URL:

The MEDIAURL is the base URL for serving media files. By default, it is set to '/media/'. To change the MEDIAURL, add the new URL as a string to the settings.py file.

MEDIA_URL = '/new/media/url/'
  1. Add URL pattern:

To serve media files, add a URL pattern to the project's urls.py file that maps to the MEDIA_ROOT.

from django.conf.urls import url
from django.conf import settings
from django.conf.urls.static import static

urlpatterns = [
    # other URL patterns
]

if settings.DEBUG:
    urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)

With these modifications, the CKEeditor field will upload images to the new specified path.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss

Add Answer


Question Tools

Stats

Asked: 2021-08-26 11:00:00 +0000

Seen: 13 times

Last updated: Nov 30 '21