Skip to content

Commit 85f09da

Browse files
committed
Use whitenoise for static file serving
1 parent fa91990 commit 85f09da

2 files changed

Lines changed: 5 additions & 0 deletions

File tree

requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,4 @@ coreapi==2.3.3
66
psycopg2==2.7.3.2
77
dj-database-url==0.4.2
88
gunicorn==19.7.1
9+
whitenoise==3.3.1

tutorial/settings.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,15 @@
3535
'django.contrib.contenttypes',
3636
'django.contrib.sessions',
3737
'django.contrib.messages',
38+
'whitenoise.runserver_nostatic',
3839
'django.contrib.staticfiles',
3940
'rest_framework',
4041
'snippets.apps.SnippetsConfig',
4142
]
4243

4344
MIDDLEWARE = [
4445
'django.middleware.security.SecurityMiddleware',
46+
'whitenoise.middleware.WhiteNoiseMiddleware',
4547
'django.contrib.sessions.middleware.SessionMiddleware',
4648
'django.middleware.common.CommonMiddleware',
4749
'django.middleware.csrf.CsrfViewMiddleware',
@@ -119,6 +121,8 @@
119121
# https://docs.djangoproject.com/en/1.11/howto/static-files/
120122

121123
STATIC_URL = '/static/'
124+
STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles')
125+
STATICFILES_STORAGE = 'whitenoise.storage.CompressedManifestStaticFilesStorage'
122126

123127
# Django REST Framework
124128
REST_FRAMEWORK = {

0 commit comments

Comments
 (0)