skip to Main Content

i have the projected is named Portfolio which is my main page.
And i have created an app named experiences on this project.

On dev server i’m able to serve static files for both. but on production, i’m only able to serve for main page (project) and not for the app. I have the 404 Not Found error.

i have make the collecstatic.

I have a static dir on each app (and project).

And i’m using apache with wsgi module.

i have this conf on settings file :

STATIC_URL = '/static/'
STATIC_ROOT = BASE_DIR / 'staticfiles'
STATICFILES_DIRS = [
    os.path.join(BASE_DIR, "Portfolio/static")
]

Below the arch :

src/
|-- Experiences
|   |-- __pycache__
|   |-- migrations
|   |   `-- __pycache__
|   |-- static
|   |   `-- Experiences
|   |       |-- assets
|   |       |   |-- fonts
|   |       |   `-- img
|   |       `-- css
|   `-- templates
|       `-- Experiences
|-- Portfolio
|   |-- __pycache__
|   |-- static
|   |   `-- Portfolio
|   |       |-- assets
|   |       |   |-- fonts
|   |       |   `-- img
|   |       `-- css
|   `-- templates
|       `-- Portfolio
`-- staticfiles
    |-- Experiences
    |   |-- assets
    |   |   |-- fonts
    |   |   `-- img
    |   `-- css
    |-- Portfolio
    |   |-- assets
    |   |   |-- fonts
    |   |   `-- img
    |   `-- css
    `-- admin

2

Answers


  1. Chosen as BEST ANSWER

    I have changed the location of the app static files. i have put all static files on the same dir.

    yacine@debian:/var/www/Portfolio/src/Portfolio$ tree static/ -d
    static/
    |-- Experiences
    |   |-- assets
    |   |   |-- fonts
    |   |   `-- img
    |   `-- css
    `-- Portfolio
        |-- assets
        |   |-- fonts
        |   `-- img
        `-- css
    

    I'm not sure that the best way but it's works for the moment.


  2. That’s expected, on dev Django serves staticfiles but on production (when debug is false) is does not, because it will lead to performance problems.

    You can check the official docs on how to configure the staticfiles in Django Docs

    If you want an easier solution, you can give a try to whitenoise

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search