Masonite Documentation
v1.3
v1.3
  • Introduction
  • Prologue
    • Introduction
    • Contributing Guide
    • How To Contribute
    • Release Cycle
  • What's New
    • Masonite 1.3
  • The Basics
    • Routing
    • Controllers
    • Views
    • Requests
    • The Craft Command
    • Static Files
    • Helper Functions
  • Architectural Concepts
    • Request Lifecycle
    • Service Providers
    • Service Container
  • Advanced
    • Middleware
    • Creating Commands
    • Creating Packages
    • Publishing Packages
    • Compiling Assets
    • Validation
    • View Composers and Sharing
    • Uploading
    • Queues and Jobs
    • Mail
      • Creating a Mail Driver
  • Security
    • Authentication
    • Encryption
  • Orator ORM
    • Basic Usage
    • Query Builder
    • ORM
    • Pagination
    • Schema Builder
    • Database Migrations
    • Collections
  • Managers and Drivers
    • About Managers
    • About Drivers
  • Official Packages
    • Masonite AuthHub
    • Masonite Clerk
    • Masonite Triggers
Powered by GitBook
On this page
  • Static Files
  • Introduction
  • Configuration
Edit on Git
Export as PDF
  1. The Basics

Static Files

Static Files

Introduction

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

Configuration

All configurations that are specific to static files can be found in config/storage.py. In this file you'll find a constant file called STATICFILES which is simply a dictionary of directories as they 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:

STATICFILES = {
    'storage/assets/css': 'css/',
}

Now in our templates we can use:

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

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

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

PreviousThe Craft CommandNextHelper Functions

Last updated 7 years ago