Lars
Lars

Reputation: 1270

Images are not showing in Production ( DEBUG =False )

I Build a WebApp and I am stuck on a Problem.

Images are not showing in Production (DEBUG = False)

settings.py

MEDIA_ROOT= '/home/new/gitrepo/main/media'
MEDIA_URL = '/media/'

STATIC_URL = '/static/'

STATIC_ROOT = '/home/new/gitrepo/static/'

What have i tried

I tried python manage.py collecstatic BUT images are still not showing in the Website.

I found many answers on this Topic like THIS. BUT it didn't worked for me.

I don't know what i am doing wrong.

Any help would be appreciated.

Thank You in Advance.

Upvotes: 0

Views: 707

Answers (1)

Zeyad Shaban
Zeyad Shaban

Reputation: 1016

Was it working in development? I think yes

open Pythonanywhere.com => choose "Web" from navbar => scroll to static files

and here you let pythonanywhere know where are the URLs for showing static data from your server

Add those two

URL                 Directory                     Delete

/static/            /home/myWebsite/static
/media/             /home/myWebsite/media

The /home/myWebsite/media is a path to where you store the static files for the given URL

here is a screenshot of my configurations My configurations

If it's not showing make sure you have something in your main URLS.py

from django.conf import settings
from django.conf.urls.static import static

urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)

Upvotes: 2

Related Questions