Skip to content

Commit

Permalink
增加静态资源版本控制
Browse files Browse the repository at this point in the history
  • Loading branch information
hhyo committed May 31, 2019
1 parent f3c17bc commit b0906fd
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
3 changes: 2 additions & 1 deletion archery/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@
STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(BASE_DIR, 'static')
STATICFILES_DIRS = [os.path.join(BASE_DIR, 'common/static'), ]
STATICFILES_STORAGE = 'common.storage.ForgivingManifestStaticFilesStorage'

# 扩展django admin里users字段用到,指定了sql/models.py里的class users
AUTH_USER_MODEL = "sql.Users"
Expand Down Expand Up @@ -130,7 +131,7 @@
},
'TEST': {
'NAME': 'test_archery',
'CHARSET': 'utf8',
'CHARSET': 'utf8mb4',
},
}
}
Expand Down
22 changes: 22 additions & 0 deletions common/storage.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# -*- coding: UTF-8 -*-
"""
@author: hhyo
@license: Apache Licence
@file: storage.py
@time: 2019/06/01
"""
__author__ = 'hhyo'

from django.contrib.staticfiles.storage import ManifestStaticFilesStorage


class ForgivingManifestStaticFilesStorage(ManifestStaticFilesStorage):
manifest_strict = False

def hashed_name(self, name, content=None, filename=None):
try:
result = super().hashed_name(name, content, filename)
except ValueError:
# When the file is missing, let's forgive and ignore that.
result = name
return result

0 comments on commit b0906fd

Please sign in to comment.