I'm making a new django app where a user can upload images and then they can be displayed on a page. I have read the django staticfiles deployment docs a bunch and don't understand why they still dont work.
All my images are going to where they're supposed to be and in the admin in my models django has the right path that leads to the image but it just won't load properly.
my setup in settings.py:
STATIC_URL = '/static/'
STATIC_ROOT = 'static' # live cdn such as AWS S3
STATICFILES_DIRS = [
os.path.join(BASE_DIR, 'static')
]
MEDIA_ROOT = os.path.join(STATIC_ROOT, 'media')
MEDIA_URL = '/img/'
my directories:
|- src
|- myproject
|- settings.py, views.py, urls.py etc
|- myapp
|- views.py urls.py models.py forms.py etc
|- static (this folder is empty and appeared after running collectstatic
|- templates
|- db.sqlite3
|- manage.py
|- static (this folder is OUTSIDE src)
|- admin
|- django admin stuff
|- media
|- img
|- myimage.png
in models.py of myapp the imagefield upload_to = 'img/'
if i am in debug mode and i add the reccomended code to make it work:
if settings.DEBUG:
from django.conf.urls.static import static
urlpatterns += static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)
urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
everything works. this is only in debug mode though. I'm aware the docs say that this only works in debug mode but i tried it anyway. I'm trying everything.
I've been trying to fix this for ages but i can't get any help from anyone and django docs and other stackoverflow questions/answers have been of no help too.
I thank you for your help!
NOTE: this is a DIFFERENT question to my previous one, please don't close it again.trying to