I have been following the official documentation to the letter, trying some of the advice for related questions on here, and just searching the web in general and I am still having no luck getting one little image to load.
I have an image called 'logo.png' and my project hierarchy looks like this:
project/
mysite/
app/
__init__.py
admin.py
models.py
urls.py
view.py
mysite/
__init__.py
settings.py
urls.py
views.py
wsgi.py
static/
logo.png
templates/
index.html
calling_image.html
Inside settings.py
I have STATIC_URL = '/static/'
Inside calling_image.html
I have <img src="/static/logo.png">
My template calling_image.html
is called by project/mysite/app/views.py
which is of course then called on by project/mysite/app/urls.py
and I even tried including the following two lines (as I saw suggested a few times) at the end of my urls.py
:
from django.contrib.staticfiles.urls import staticfiles_urlpatterns
urlpatterns += staticfiles_urlpatterns()
Nothing works, so what have I done wrong?
Edit: Sorry I made a type, I have STATIC_URL = '/static/'
with the closing slash in my settings.py
and for clarification, I am running this on my dev build with python manage.py runserver
Solved: So I ended up solving this myself. I created a directory resources
within project/mysite/
and placed logo.png
in there. I then set STATICFILES_DIRS = (os.path.join(BASE_DIR, "resources"),)
and ran collecstatic
and everything worked! Didn't need to use urlpatterns += staticfiles_urlpatterns()
and whatnot.