Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

415
Views
Django 4 Static files : what's the best practice

I'm currently building a project on Django 4.0 and I want to do the static files management the best and the cleaner for this version.

Currently I have this project tree :

enter image description here

And here is my settings file :

BASE_DIR = Path(__file__).resolve().parent.parent.parent
(...)
STATIC_URL = '/static/'
STATICFILES_DIRS = [
    os.path.join(BASE_DIR, 'static'),
]

When I try to find some videos about the subject, no one is using the same structure and setup for static files. In this sample, I have a 404 error on my dist/css/output.css file.

In my HTML template I try to call it that way :

<link href='{% static "css/dist/output.css" %}' type="text/css" rel="stylesheet">

Could someone please copy/past me an easy static setup for handling static properly ? Or at least, help me to understand why it doesn't work and what I should do ?

Moreover, I put my static directory outside my main app, but some are putting it in. So I don't know what's best...

Thanks :)

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

The best way to configure your static files in django 4 is to use pathlib instead of importing an extra module eg. os

STATICFILES_DIRS = [
    BASE_DIR / "static",
]

and problem is that you don't have css folder inside your static folder so instead of this

<link href='{% static "css/dist/output.css" %}' type="text/css" rel="stylesheet">

you have to put this

<link href='{% static "dist/output.css" %}' type="text/css" rel="stylesheet">

or you can create css folder and add dist folder inside it

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!