[PYTHON] Django static file (static) related settings summary

environment

Python 3.4.3 Django 1.10 uwsgi Nginx CentOS7.2 @ Sakura VPS

why

When deploying Django to the production environment, I got stuck in static file related settings, so I will summarize it. It seems that there are basically the following five, but since I used only the top three, I will summarize them. By the way, each of the following constants is set in setting.py.

https://docs.djangoproject.com/en/1.10/ref/settings/#id17

STATIC_ROOT Static files did not work well in production unless this was set correctly. Actually, the css and images of the management site and the normal site were not applied or displayed.

In my case, I set it as follows. STATIC_ROOT points to the actual absolute path on Linux.

setting.py


# Fetch Django's project directory
DJANGO_ROOT = dirname(dirname(abspath(__file__)))
# Fetch the project_root
PROJECT_ROOT = dirname(DJANGO_ROOT)

STATIC_ROOT = os.path.join(PROJECT_ROOT, 'static') # /path/to/project_directory/static

Absolute path to the directory where collectstatic collects static files for the deployment environment The absolute path to the directory where collectstatic will collect static files for deployment.

Example: "/var/www/example.com/static/"

STATIC_URL¶ For the time being, set it to / static /. Then, it seems that the static file will be read to domain / static /.

URL used when referencing static files located in STATIC_ROOT URL to use when referring to static files located in STATIC_ROOT. Example: "/static/" or "http://static.example.com/"

STATICFILES_DIRS¶ Maybe you need to set it when you have additional static files for each app. In my environment, I didn't need a static file for each application for the time being, so I didn't set it.

Recommended Posts

Django static file (static) related settings summary
[Django] About static file related settings (images, videos)
[Django] About static file related settings (css, js)
Django tutorial summary for beginners by beginners ⑥ (static file)
Django Summary
Django related sites
django default settings
Django filter summary
Django + MySQL settings
python related summary
Django URL settings
Kaggle related summary
[Django3] Environment construction and various settings summary [Python3]
Django template file organization
Python Django tutorial summary
Apache + Django + Shibboleth on Windows Server 2016 Related Articles Summary
keyhac Personal settings summary
File upload with django
Python iteration related summary
Django / Related objects (add, create, remove, clear, set) Summary
Django command completion settings
Image related command summary
Summary of python file operations
Remote related settings in pycharm
DEBUG settings when using Django
django timezone and language settings
About handling Django static files
Summary of Proxy connection settings
[Learning memo] Django command summary