4
我在django中有点新,并且我在我的模型中使用了stdimage模块。当我通过管理员上传图片并保存,在打开的模型对象我觉得有三样东西管理员中的无效stdmage图像路径
领域- 当前图像:这给链接已上传的图片如uploaded_images/2012/11/28 /人map_7.jpeg
- 更改:这是提供更改图像
- 删除:用复选框删除上传的图像。 当我添加一个图像并保存该对象时,我得到/ admin/oxer/site/41 /上的错误IOError,当我点击图像链接时,我得到404错误,图像URL显示为itech.com/admin/ oxer/site/49/uploaded_images/2012/11/04/image_1.jpeg而不是itech.com/static/uploaded_images/2012/11/04/image_1.jpeg(请注意,我已将'admin/oxer/site/49 '并替换为'静态')。
我想ioerror是由错误的网址带来的。我怎么能让它有正确的网址?
这里是我的模型:
class Site(CommonMixin, ImageMixin):
__metaclass__ = TransMeta
name = models.CharField(max_length=255, verbose_name=_("Name"))
description = models.TextField(verbose_name=_("Description"))
has_airport = models.BooleanField(default=False)
rating = models.IntegerField()
order = models.IntegerField()
do_not_miss = models.TextField(verbose_name=_("Do not miss"))
recommended_stay = models.TextField(verbose_name=_("Recommended stay"))
address = models.CharField(max_length=255, verbose_name=_("Address"))
state = models.CharField(max_length=100, verbose_name=_("State"))
price = models.TextField(verbose_name=_("Price"))
good_to_know = models.TextField(verbose_name=_("Good to know"))
link = models.URLField(blank=True, null=True)
region = models.ManyToManyField('Region', blank=True, null=True)
interests = models.ManyToManyField('Interest', blank=True, null=True)
map = StdImageField(
upload_to='uploaded_images/%Y/%m/%d',
max_length=255,
height_field='height',
width_field='width',
size=(453, 294, True),
thumbnail_size=(195, 150, True),
blank=True,
null=True
)
location_lat = models.DecimalField(
u'Location (latitude)', max_digits=10, decimal_places=7, default=0,
help_text=u"You can use http://www.getlatlon.com to get a location's coordinates"
)
location_lon = models.DecimalField(
u'Location (longitude)', max_digits=10, decimal_places=7, default=0,
help_text=u"You can use http://www.getlatlon.com to get a location's coordinates"
)
加入MEDIA_URL = '/媒体/',图像后路径现在变成itech.com/media/uploaded_images/2012/11/28/map_7.jpeg,因为stdimage正在使用MEDIA_URL的值。它会在点击时带来404错误,因为我的STATIC_URL ='/ static /'。问题是,路径应该是itech.com/static/uploaded_images/2012/11/28/map_7.jpeg,以显示图像。我无法为STATIC和MEDIA_URL使用相同的值。任何帮助? – Alexxio
我通过STATIC_URL ='/ static /'和MEDIA_URL ='/ static \ t /'修复了它。我不知道'\ t'是否会对该项目产生任何影响。谢谢史蒂夫。正如你所建议的那样,MEDIA_URL ='...'是需要的,所以它的val会放到itech.com/"HERE"/uploaded_images/2012/1/28/map_7.jpeg。它现在工作。当我点击链接时,图像显示。 – Alexxio