0

I've just deployed a site with pythonanywhere, when I set to DEBUG mode to False, my media images dissapear, the path of my media folder is not found. I was asking myself what causes this issue and how I can resolve it ?

Here is how I configured my settings :

STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles')

MEDIA_ROOT = os.path.join(BASE_DIR, 'media')
MEDIA_URL = '/media/'

urls.py

urlpatterns = [
    ...
] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
Raja Simon
  • 10,126
  • 5
  • 43
  • 74
Horai Nuri
  • 5,358
  • 16
  • 75
  • 127

2 Answers2

2

Found it, with pythonanywhere I had to setup media on the static files handler like this :

path : /media/

directory : /home/<myusername>/<myproject>/media

Then reload the domain name after setting DEBUG to False.

Horai Nuri
  • 5,358
  • 16
  • 75
  • 127
  • can you give more details? e.g. the source of the information and the config lines and commands you ended up using? – Nils Werner Feb 28 '17 at 11:35
  • 1
    there is a built in static file handler in pythonanywhere, you can read more [here](https://help.pythonanywhere.com/pages/DjangoStaticFiles) about it. – Horai Nuri Feb 28 '17 at 11:39
1

The behaviour you are seeing is by design, Django doesn't serve static files in production mode. Serving many, potentially huge static files using Python will put a lot of stress on the server, while any of the common servers will handle that with ease.

Hence you need to serve them using Apache or nginx yourself: https://docs.djangoproject.com/en/1.10/howto/static-files/deployment/

Nils Werner
  • 34,832
  • 7
  • 76
  • 98