1

I've been going at this for about 3 hours now and I'm completely lost and running in circles. I'm trying to get my static and media files into deployment.

My settings file looks like this:

DEBUG = False 

...

STATIC_ROOT = '/home/huhu/webapps/eng30_static_media/static'
MEDIA_ROOT =  '/home/huhu/webapps/eng30_static_media/media'

STATIC_URL = '/static/'
MEDIA_URL = '/media/'

I've run collectstatic and my static files are in /home/huhu/webapps/eng30_static_media/static I still have no idea what to do with the media files. What am I missing here? I currently don't have any static js, static img, static css, or media uploaded via the admin panel showing.

  • Nothing. Once you upload something through your site or admin, MEDIA_ROOT directory will me created and the file saved there. – Andrey Shipilov Oct 20 '16 at 01:25
  • You should provide more context, what is your server type, what deployment method, what web server? – Selcuk Oct 20 '16 at 01:25
  • Take a look at http://djangodeployment.com/2016/10/18/checklist-for-django-settings-on-deployment/ and check the web server log files at `/var/log/nginx/error.log` or `/var/log/apache2/error.log`. – Antonis Christofides Oct 20 '16 at 06:04

2 Answers2

1

If you are using nginx, you would add the following location to your server block

location /static/ {
    root /home/huhu/webapps/eng30_static_media;
}

Because you have DEBUG set to False, django will not serve the staticfiles for you in production like it does on your dev server. This is by design because, as the documentation notes, the staticfiles application is grossly inefficient and may be insecure: https://docs.djangoproject.com/en/1.10/howto/static-files/

2ps
  • 15,099
  • 2
  • 27
  • 47
1

Open your browser console and see the response that is returned when fetching static files.

You have to let your web server serve files. Make sure that your web server (apache/nginx) have proper permissions to access the static directory, which in your case '/home/huhu/webapps/eng30_static_media/static'. If you will still be facing issues, then move static files to /var/www/static directory if you are using apache and change your static root to

STATIC_ROOT = '/var/www/static'

Check permissions/ownership on files using ls -l

ls -l
-rw-r--r-- 1 www-data www-data 11321 Jul 28 17:08 index.html

for apache user/group www-data/www-data must have access on files that needs to be served through server. If files are owned by others, try a chown on the files/directories to change ownership.

chown -R chown -R username:group directory

If you are using nginx, then define your static files directory in nginx conf and try reloading the page.

cutteeth
  • 2,148
  • 3
  • 25
  • 45