Reputation: 1943
I'm trying to add some features into my existing app called school. At the moment I'm trying to add a picture into my template but all the template does it just display an empty box.
I'm reading Manging static file and I learn't how to display a picture hard coded but when I try to display a picture like this. It doesn't seem to work.
<img src="{{ STATIC_URL }}images/Crater.jpg" />
Here my setting : it was too long to post here
and my index.html template
{% if students %}
<ul>
{% for student in students %}
<li><a href="{% url school:cat student.id %}">{{student.id}} {{student.First_name}}</li>
{% endfor %}
</ul>
{% endif %}
<img src="{{ STATIC_URL }}images/Crater.jpg" />
Upvotes: 0
Views: 359
Reputation: 22808
STATICFILES_DIRS = (
# Put strings here, like "/home/html/static" or "C:/www/django/static".
# Always use forward slashes, even on Windows.
# Don't forget to use absolute paths, not relative paths.
os.path.join(SITE_ROOT, 'staticfiles'),
)
//Or try in your template
{% load static %}
<img src="{% static 'images/Crater.jpg' %}" />
Upvotes: 1
Reputation: 2811
Can you please try this out .
settings.py
MEDIA_URL = '/static_media/'
STATIC_ROOT = ''
# URL prefix for static files.
# Example: "http://media.lawrence.com/static/"
STATIC_URL = '/static/'
Now in urls.py
if settings.DEBUG:
urlpatterns += patterns('django.views.static',
(r'^static_media/(?P<path>.*)$',
'serve', {
'document_root': '/your/static/folder/path/',
'show_indexes': True }),)
And in template try like this
put your images in static direcory
And access like
<img src="{{MEDIA_URL}}your.jpeg">
I am just giving you and css example there you can try with images as well
Upvotes: 0
Reputation: 10162
You should specify the paths of your static files in your settings and the run "collect static files". Read carefully the documentation. Here is an extract of your settings file:
# Additional locations of static files
STATICFILES_DIRS = (
# Put strings here, like "/home/html/static" or "C:/www/django/static".
# Always use forward slashes, even on Windows.
# Don't forget to use absolute paths, not relative paths.
)
Upvotes: 1
Reputation: 2080
One thing to look after is to make sure you have {% load staticfiles %}
at the beginning of your template assuming you're using Django 1.4+ if you're using 1.3 it would be {% load static %}
I guess.
Upvotes: 1