Python 3.4.3 Django 1.10 uwsgi Nginx CentOS7.2 @ Sakura VPS
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