I have a django app running on cpanel (I’m not sure if is a problem of my
django app or cpanel server), when the debug mode is set up True
. I can see all the media files, like profiles pictures or pdf files, etc. But when the debug mode is set up False
, you can’t see the media files on the app. This is my configuratios on the settings.py
file.
STATICFILES_DIRS = [
os.path.join(BASE_DIR, 'static'),
]
STATIC_URL = '/static/'
STATIC_ROOT = '<app-directory>/public_html/static'
# Media files
MEDIA_ROOT = os.path.join(BASE_DIR, 'media')
MEDIA_URL = '/media/'
# Crispy Form Theme - Bootstrap 3
CRISPY_TEMPLATE_PACK = 'bootstrap3'
# For Bootstrap 3, change error alert to 'danger'
from django.contrib import messages
MESSAGE_TAGS = {
messages.ERROR: 'danger'
}
3
Answers
To deploy a production server, you need to set 3 things
This disable all extra function for development.
This, indicate where all the static files should be saved.
This saves all statics files in the directory configured by
STATIC_ROOT
The official documentation for deployment:
https://docs.djangoproject.com/en/2.1/howto/deployment/checklist/#static-root-and-static-url
I don’t actually solve it yet but you can do as below to solve your issue:
1 – Setup your media and static root:
2 – Activate your virtual enviroment on cpanel then run this command:
3 – After you did that 2 folder will create at root of your app on cpanel
"static" and "media" folder copy both of them into "public_html" directory
4 – go to the setup python app in cpanel and find your app and restart it.
It will solve the issue for me but every time when i upload some picture i should go and just copy the media files into public_html
I have this issue for 1 day but I found solution. You can install this two packages dj-static static3 with pip:
then change your wsgi.py file like below: