DEV Community

Cover image for Bring in the WhiteNoise, Bring in Da Funk - Building SaaS #34
Matt Layman
Matt Layman

Posted on β€’ Originally published at mattlayman.com

Bring in the WhiteNoise, Bring in Da Funk - Building SaaS #34

In this episode, we added WhiteNoise to the app as a tool for handling static assets. This lets us move away from depending on Nginx for the task and gives shiny new features like Brotli support.

We installed WhiteNoise into the requirements.in file and used pip-tools to generate a new requirements.txt.

whitenoise[brotli]==4.1.4

Once WhiteNoise was installed, it needed two primary settings changes.

  1. Add a new middleware.
  2. Change the STATICFILES_STORAGE.
MIDDLEWARE = [
    ...
    "whitenoise.middleware.WhiteNoiseMiddleware",
    ...
]

STATICFILES_STORAGE = \
    "whitenoise.storage.CompressedManifestStaticFilesStorage"

This was enough to get WhiteNoise working. We checked the local development server, and the site continued to operate normally.

Unfortunately, the configuration was not enough to make static assets work with the Shiv app. Since STATIC_ROOT used a relative value of static, Shiv couldn't find the static files. This relative pathing was the same problem I faced when getting the templates directory working with the Shiv app. We used the same solution and switched to:

import conductor

conductor_dir = os.path.dirname(conductor.__file__)
STATIC_ROOT = os.path.join(conductor_dir, "static")

Finally, we needed to make the conductor package hold the collected static files. We could do this by tweaking MANIFEST.in with the following addition:

recursive-include conductor/static *

On the next stream, we'll make some CI changes and update deployment to discontinue use of Nginx for serving static files.

This article first appeared on mattlayman.com.

Quadratic AI

Quadratic AI – The Spreadsheet with AI, Code, and Connections

  • AI-Powered Insights: Ask questions in plain English and get instant visualizations
  • Multi-Language Support: Seamlessly switch between Python, SQL, and JavaScript in one workspace
  • Zero Setup Required: Connect to databases or drag-and-drop files straight from your browser
  • Live Collaboration: Work together in real-time, no matter where your team is located
  • Beyond Formulas: Tackle complex analysis that traditional spreadsheets can't handle

Get started for free.

Watch The Demo πŸ“Šβœ¨

Top comments (0)

AWS Security LIVE!

Tune in for AWS Security LIVE!

Join AWS Security LIVE! for expert insights and actionable tips to protect your organization and keep security teams prepared.

Learn More

πŸ‘‹ Kindness is contagious

Explore a trove of insights in this engaging article, celebrated within our welcoming DEV Community. Developers from every background are invited to join and enhance our shared wisdom.

A genuine "thank you" can truly uplift someone’s day. Feel free to express your gratitude in the comments below!

On DEV, our collective exchange of knowledge lightens the road ahead and strengthens our community bonds. Found something valuable here? A small thank you to the author can make a big difference.

Okay