user984003
user984003

Reputation: 29527

Site on localhost not displaying image

I am trying to get an image to appear using Django template.

In settings I have:

MEDIA_ROOT = 'C:/workspace/mysite/uploaded_media/'
MEDIA_URL = 'http://localhost:8000/mysite/media/'

The html is

<img source = "http://localhost:8000/mysite/media/blabla.jpg"></img>

I have an image file blabla.jpg in the folder uploaded_media

What am I missing here?

Edit: first problem was writing "source" instead of "src" in the tag. doh. (attempting the answer below right now.)

Upvotes: 1

Views: 3801

Answers (1)

abidibo
abidibo

Reputation: 4287

try

MEDIA_URL = '/media/'

and in template

<img src="/media/blabla.jpg" />

Also put these lines of code inside your urls.py and set DEBUG to True

if settings.DEBUG:
  # static files (images, css, javascript, etc.)
  urlpatterns += patterns('',
    (r'^media/(?P<path>.*)$', 'django.views.static.serve', {
    'document_root': settings.MEDIA_ROOT}))

Upvotes: 2

Related Questions