我有一個允許用戶上傳圖像的頁面,該圖像由models.py文件存儲在{{MEDIA_ROOT}}/image/image1.jpg中 i要通過HTML圖像標記另一個網頁上顯示此圖像顯示用戶在django上傳的圖像
我的HTML代碼片段是<img border="2" src="{{ MEDIA_URL }}/images/{{ghar.image}}" alt="venture picture here"/>
這裏加爾的是,具有ABT圖像細節的對象
誰能幫我做相同
我使用的Django的框架和sqlite3的爲DB
更新:
這是我的models.py功能
from django.db import models
class GharData(models.Model):
place = models.CharField(max_length=40)
typeOfProperty = models.CharField(max_length=30)
typeOfPlace = models.CharField(max_length=20)
price = models.IntegerField()
ownerName = models.CharField(max_length=80)
ownerEmail = models.EmailField(blank=True, null=True)
address = models.CharField(max_length=200)
nameOfVenture = models.CharField(max_length=100)
city = models.CharField(max_length=60)
size = models.CharField(max_length=60)
designedBy = models.CharField(max_length=50,blank=True,null=True)
description = models.CharField(max_length=500,blank=True,null=True)
ownerPhone = models.CharField(max_length=20)
def __unicode__(self):
return self.ownerName
class ImageData(models.Model):
property = models.ForeignKey(GharData, related_name='images')
image = models.ImageField(upload_to='image/',blank=True,null=True)
video = models.FileField(upload_to='video/',blank=True,null=True)
def __unicode__(self):
return self.property.ownerName
這是urls.py
from django.conf.urls.defaults import patterns, include, url
import settings
# Uncomment the next two lines to enable the admin:
from django.contrib import admin
admin.autodiscover()
urlpatterns = patterns('',
url(r'^$', 'gharnivas.views.index'),
url(r'^search/$', 'gharnivas.views.search'),
url(r'^venture/(?P<ghar_id>\d+)/$', 'gharnivas.views.venture'),
url(r'^media/(?P<path>.*)$','django.views.static.serve',{'document_root': settings.MEDIA_ROOT}),
url(r'^admin/', include(admin.site.urls)),
)
非常感謝
@DrTyrsa:它沒有工作......我沒有得到的圖像 – 2011-05-05 08:52:20
你在模型中使用'upload_to'?或者手動上傳某種方式?如果第二個 - src =「{{MEDIA_URL}}/{{ghar.image.name}}」'(或'src =「{{MEDIA_URL}}/images/{{ghar.image.name}}」') – DrTyrsa 2011-05-05 09:06:14
@DrTr莎莎:我已經更新了這個問題。你能否檢查一下,請讓我知道我的錯誤? – 2011-05-05 09:10:41