Problem With Serving Pictures In Django
Solution 1:
use:
MEDIA_URL = 'http://localhost:8000/static/'
or
MEDIA_URL = '/static/'
Solution 2:
Your MEDIA_URL
should just be '/static/'
- or, if you must, 'http://localhost:8000/static/'
. Otherwise your browser is interpreting the localhost
as part of the path, not the domain.
Solution 3:
Ok, I feel very stupid... I had to change
MEDIA_URL = 'localhost:8000/static/'
to
MEDIA_URL = 'http://localhost:8000/static/'
and then I had change
<img src="{{MEDIA_URL}}{{a.picture.url}}">
to
<img src="{{a.picture.url}}">
Thank you for your time.
Solution 4:
What version of Django are you using?
Can you post the generated HTML code? if the URL works when you copy and paste in the browser, it might be an html issue as well.
Have you looked at this page yet?
http://docs.djangoproject.com/en/dev/howto/static-files/
Update:
Can you post the model for a? is a.picture an image field? If so, then you don't need to put the MEDIA_URL in your img src, since it is already an absolute url and it should include the MEDIA_URL already. try removing that and see if it works.
<img src='{{a.picture.url}}' />
For more info see this page.
http://docs.djangoproject.com/en/1.3/ref/models/fields/#django.db.models.FileField.storage
Post a Comment for "Problem With Serving Pictures In Django"