简体   繁体   中英

The Django project that has been debugged locally is deployed to the centos7 server

The Django project that has been debugged locally is deployed to the centos7 server, and it is found that the static file images and CSS cannot be found, but there is no problem in the local debugging process before. How to deploy the static files in the server. I have searched a lot of questions on the Internet, but I have not solved this problem. Thanks

First of all make sure that you have defined STATIC_ROOT and STATIC_URL in your project's settings.py :

STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(BASE_DIR, 'static/')

After that use django management command (ie python manage.py collectstatic ) to collect your static files (Note: Use this command on your server not on your local machine). Then add config of static root directory to your web server project's configs for serving static files and I don't know which web server you're using at the moment (Ex: Nginx) and finally reload your web server to update the old configs.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM