B
B
blackbb2016-01-17 13:45:58
Django
blackbb, 2016-01-17 13:45:58

How to properly configure media-root?

There is a project hosted by jino.ru. The project is in the django/project folder. The static and media folders are removed from the project and are located in the domains/mysite.ru/ folder
in settings.py:
STATIC_ROOT = os.path.join(BASE_DIR,'static')
STATIC_URL = '/static/'
MEDIA_ROOT = os.path.join (BASE_DIR,'media')
MEDIA_URL = '/media/'
When adding new images to the object through the admin panel, all images are placed in the media folder, but in the project, i.e. in django/project, and not in domains/mysite.ru / and therefore these images are not displayed on the site. Tell me how to deal with it.
In urls.py I wrote urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
urlpatterns += staticfiles_urlpatterns()

Answer the question

In order to leave comments, you need to log in

2 answer(s)
P
Peter, 2016-01-17
@blackbb

I did through the link of the django/project/static directory in domains/mysite.ru/static
For media, you can also

N
neatsoft, 2016-01-17
@neatsoft

MYSITE_URL = '<abs_path>/domains/mysite.ru'
STATIC_ROOT = os.path.join(MYSITE_URL, 'static')
MEDIA_ROOT = os.path.join(MYSITE_URL, 'media')

But this is not suitable for production. The static directory must be distributed using nginx (after linking it with python manage.py collectstatic), and media must be moved to a separate domain (to prevent XSS vulnerabilities).

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question