#Static and media files in production

32 messages · Page 1 of 1 (latest)

shy pond
#

Hello,

I try to deploy my website. My host provides the cPanel interface which gives many tools, especially the "Setup Python app" which is a quick way to deploy Python app.
My website is deployed, but all the media / static files are not taken into account.

Here is what I did :

  • debug is set to False
  • The static folder used during development is under an app called "general". So general -> static -> general -> main.css, ...
  • I set the variables as followed :
STATIC_ROOT = BASE_DIR / 'static'
STATIC_URL = '/static/'

MEDIA_ROOT = BASE_DIR / 'media'
MEDIA_URL = '/media/'
  • I ran "python manage.py collectstatic" and a new folder in the BASE_DIR of my project called "static" has been created.

I feel like I miss something cause it doesn't work. I suspect the fact that my static folder used under development is part of the "general" app and the path given to the STATIC_ROOT and STATIC_URL are not good...

Any idea ? Thanks in advance.

late jay
#

When DEBUG=False, Django do not serve static files.
You need a reverse proxy like nginx... Or even better, use whitenoise (https://whitenoise.readthedocs.io/en/latest/)

I am using Whitenoise in a Digital Ocean app platform lately so I highly recommend it.

shy pond
#

Ok, but what is your configuration of your settings.py file ? Especially the paths given to the variables STATIC_ROOT, MEDIA_ROOT, etc.

steel current
#

Note that white noise also doesn't support media files. Only static files.

late jay
#

I use the same config as you have + whitenoise-related settings.

shy pond
#

And where is located your initial static folder you used during dev ?

#

Does its location matter ?

late jay
#

Name should be the same as in the settings, I think

#

Note that white noise also doesn't support media files. Only static files.

whitenoise is not recommend for media files. You can use django-storages with any service of your choice

shy pond
steel current
shy pond
#

The doc is quite limited actually, for what I've read. It's O2Switch

late jay
#

Of course number 1 is not recommended

shy pond
#

IT'S WORKING FOR THE STATIC FILES ! With whitenoise ! Thanks !

#

It's time for the media now 😄

steel current
#

Can you show me a screenshot of the Section avancé / Gestionnaires Apache?

steel current
#

Not sure. I don't have access to the panel 😁
https://faq.o2switch.fr/hebergement-mutualise/tutoriels-cpanel

shy pond
#

Sent it to you in mp

steel current
#

Yeah, that doesn't look like it allows you to properly configure Apache... Only file extensions.

shy pond
#

@late jay for your information, for the static files, I had to add this line to make it work :

STATICFILES_DIRS = [ BASE_DIR / 'general/static' ]

Because my static folder was not in the root of my project

shy pond
steel current
#

Not sure. If you're down to have a video call with a shared screen, I could have a look tomorrow...
Right now, the best way I'm thinking is to use subdomains like static.example.com and media.example.com to serve those files...

shy pond
#

That'd be great !

steel current
#

That would allow you to configure the python app on your main domain, and have Apache serve the subdomains directly 🤔

#

It's been a while since I've used cPanel and it wasn't with Django though 😄

#

Ping or DM me tomorrow. I presume you're around France time, based on your host?

shy pond
#

You're right, and you ?

steel current
#

An hour ahead, I think. Helsinki time.

shy pond
#

Ok let's catch tomorrow then 🙂 thanks !

steel current
#

In the meantime, you can look at the link I sent. If you play around with (sub)domain settings, you might figure something out 😄