I want to see an exception, if settings.DEBUG is true and line like this gets processed by the template engine:
<link rel="stylesheet" type="text/css"
href="{% static "foo/css/file-name-with-typo.css" %}">
Docs for the static
template tag: https://docs.djangoproject.com/en/1.9/ref/contrib/staticfiles/#static
Background: An exception would trigger our Continous Integration system to fail and the broken could would not go live. I don't want to run code in production which produces broken links.
Override the url()
method to raise an error if the file doesn't exist:
from django.core.files.storage import FileSystemStorage
class CustomFileSystemStorage(FileSystemStorage):
def url(self, name):
if not self.exists(name):
raise ValueError('"%s" does not exist.' % name)
return super(CustomFileSystemStorage, self).url(name)
In your settings.py:
DEFAULT_FILE_STORAGE = 'mymodule.CustomFileSystemStorage'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With