ユーザーが画像をアップロードできるページがあり、その画像は models.py ファイルによって {{MEDIA_ROOT}}/image/image1.jpg に保存されています。別の Web で html 画像タグを使用してこの画像を表示したいページ
私のhtmlコードスニペットは<img border="2" src="{{ MEDIA_URL }}/images/{{ghar.image}}" alt="venture picture here"/>
ここで ghar は、画像に関する詳細を持つオブジェクトです
誰でも同じことをするのを手伝ってもらえますか
私は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)),
)
事前にどうもありがとう