1 Replies - 713 Views - Last Post: 24 July 2012 - 10:48 AM Rate Topic: -----

#1 listentodata  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 09-July 12

Django: I just want to display an image <img>, 4 days searchin

Posted 24 July 2012 - 10:45 AM

Hello everyone,
I am using django to create a website. I have spent days on an in vain inquire: I just want to display an image in my website. when I use <img src='...> the server shows a blanc page. Even when I see the source code of the home.html rendered by the server, I find a correct html code but, the image is not displayed. I will be grateful if anyone helps me because this trick took so much time. It becomes like a big stumbling bloc.
Models
from django.db import models

class img(models.Model):
    title = models.CharField(max_length=200)
    donnee = models.ImageField(upload_to='photos')

class snd(models.Model):
    imgnd = models.ForeignKey(img)
    title = models.CharField(max_length=200)



Views
from gifs.models import img
from django.shortcuts import render_to_response

def finale(request):
	s=img.objects.get(id=1)
	p=s.donnee
	return render_to_response('home.html', {'p': p})



Template home.html

<img src='C:/Users/Me/Desktop/internship/medias/{{p}}' />



URLs
from django.conf.urls import patterns, include, url
from django.contrib import admin
admin.autodiscover()

urlpatterns = patterns('',
    url(r'^home', 'gifs.views.finale'),
    url(r'^admin/', include(admin.site.urls)),
)



Is This A Good Question/Topic? 0
  • +

Replies To: Django: I just want to display an image <img>, 4 days searchin

#2 atraub  Icon User is offline

  • Pythoneer
  • member icon

Reputation: 756
  • View blog
  • Posts: 1,990
  • Joined: 23-December 08

Re: Django: I just want to display an image <img>, 4 days searchin

Posted 24 July 2012 - 10:48 AM

2 quick things.

First off, your img tag needs an alt tag.

Secondly, do you see the img tag when you look at the page's source? Could you copy and paste that from the source for us?

This post has been edited by atraub: 24 July 2012 - 10:49 AM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1