Try using files such as CSS and Js files in Python.
First of all, my server is a combination of Nginx + Gunicorn, so Set the distribution of Nginx
Create an address alias for / static
location /static {
alias /app/sampleProj/sampleProj/static;
}
Then set up a static folder in Django Edit setting.py in the app
setting.py
STATIC_ROOT = os.path.join(BASE_DIR, 'sampleProj/static')
STATIC_URL = '/static/'
** * BASE_DIR is a constant set by Django. It will be the directory where manage.py exists ** You can set it with a relative path from the base directory.
By default, Django sets static files in the Django installation folder installed by pip. So type the command to make the current folder a static file
python manage.py collectstatic
Complete with this! Sexual files such as CSS and JS have been set up in Django
You can check the added static file directory with the following command!
python manage.py findstatic .
Reference URL
Getting Started with Django | Settings for reading static files with Nginx https://dot-blog.jp/news/django-nginx-static-load/ Easy-to-understand explanation of BASE_DIR [This will give you an idea of the location and structure] https://codor.co.jp/django/about-basedir
Recommended Posts