What's New
Upgrade Guide
The Basics
The Craft Command
Architectural Concepts
Useful Features
Orator ORM
Managers and Drivers
Official Packages
Masonite Essentials
How-to Guides

Static Files


Masonite tries to make static files extremely easy and comes with whitenoise out of the box. Whitenoise wraps the WSGI application and listens for certain URI requests that can be resistered in your configuration files.


All configurations that are specific to static files can be found in config/ In this file you'll find a constant file called STATICFILES which is simply a dictionary of directories as keys and aliases as the value.

The directories to include as keys is simply the location of your static file locations. For example, if your css files are in storage/assets/css then put that folder location as the key. For the value, put the alias you want to use in your templates. For this example, we will use css/ as the alias.

For this setup, our STATICFILES constant should look like:

'storage/assets/css': 'assets/',

Now in our templates we can use:

<img src="/assets/style.css">

Which will get the storage/assets/css/style.css file.

Static Template Function

All templates have a static function that can be used to assist in getting locations of static files. You can specify the driver and locations you want using the driver name or dot notation.

Take this for example:

's3': {
's3_client': 'sIS8shn...'
'location': ''
<img src="{{ static('s3', 'profile.jpg') }}" alt="profile">

this will render:

<img src="" alt="profile">

You can also make the config location a dictionary and use dot notation:

's3': {
's3_client': 'sIS8shn...'
'location': {
'east': '',
'west': ''

and use the dot notation like so:

<img src="{{ static('s3.east', 'profile.jpg') }}" alt="profile">
<img src="{{ static('s3.west', 'profile.jpg') }}" alt="profile">

Static Helper

You have the ability to use the static helper outside of templates by doing:

from masonite.helpers import static

The implementation is the same as above.

Serving "Root" Files

Sometimes you may need to serve files that are normally in the root of your application such as a robots.txt or manifest.json. These files can be aliased in your STATICFILES directory in config/ They do not have to be in the root of your project but instead could be in a storage/root or storage/public directory and aliased with a simple /.

For example a basic setup would have this as your directory:


and you can alias this in your STATICFILES constant:

# folder # template alias
'storage/static': 'static/',
'storage/root': '/'

You will now be able to access localhost:8000/robots.txt and you will have your robots.txt served correctly and it can be indexed by search engines properly.

Thats it! Static files are extremely simple. You are now a master at static files!