Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Force Django ManifestStaticFilesStorage to always return urls with hashes

By default, ManifestStaticFilesStorage only returns urls with hashes in them when DEBUG=False. I want my development environment to be as close to production as possible, but I do need to set debug to False for a couple of things during development. Is there a way to tell ManifestStaticFilesStorage to always give me the url with hash?

like image 465
bigblind Avatar asked Feb 22 '16 20:02

bigblind


1 Answers

You could override the url method of ManifestStaticFilesStorage so that it always gives you the url with the hash.

from django.contrib.staticfiles.storage import ManifestStaticFilesStorage
from django.conf import settings


class BigBlindManifestStaticFilesStorage(ManifestStaticFilesStorage):

    def url(self, name, force=True):
        """
        Override .url to use hashed url in development
        """
        return super(ManifestStaticFilesStorage, self).url(name, True)
like image 158
ben432rew Avatar answered Nov 15 '22 05:11

ben432rew