I came from PHP, Python and Django are new to me. I have a simple problem but have already stuck with this for hours and still couldn't find out what went wrong.
I want to insert a simple image into the template.
I have followed TemplateSyntaxError 'staticfiles' is not a valid tag library' and https://docs.djangoproject.com/en/1.3/howto/static-files/#with-a-template-tag
Following are my settings.
- my static folder is located in
/myproject/myapp/static/
. And the img path is/static/images/hi.jpg
. - the src value in img tag is
"/static/images/hi.jpg"
when the page is rendered - Setting in setting.py
STATIC_URL = '/static/' INSTALLED_APPS = ( 'django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.sites', django.contrib.messages', 'django.contrib.staticfiles', 'myapp', 'django.contrib.admin')
In template, I have
{% load static %} {% get_static_prefix as STATIC_PREFIX %}
and the source part of the image
src="{{ STATIC_PREFIX }}images/hi.jpg"
- finally, the url of the app is http://127.0.0.1:8000/myapp/
what part is wrongly configured? Any idea? Thank you so much for the help. Sorry for the poor formatting.