django-photologue 为照片构建了错误的 URL
我已经安装了 django-photologue 并向数据库添加了一些照片。基本的网站机制似乎运行良好,但没有显示照片或缩略图。图像和缩略图位于 ..\django\media\photologue\photos 中。
对于 photo_detail 页面,生成的 HTML 源代码如下所示:
<title>Greece 3</title>
<h1>Greece 3</h1>
<div class="gallery-photo">
<a href="photologue/photos/greece003.jpg"><img src="photologue/photos/cache/greece003_display.jpg" alt="Greece 3"/></a>
<p>no caption yet</p>
</div>
<h2>This photo is found in the following galleries:</h2>
<ol>
<li>
<a title="Greece 2" href="/photologue/photo/greece-2/"><img src="photologue/photos/cache/greece002_thumbnail.jpg"/></a>
<a href="/photologue/gallery/greece/">LSB Photos - Greece</a>
<a title="Greece 4" href="/photologue/photo/greece-4/"><img src="photologue/photos/cache/greece004_thumbnail.jpg"/></a>
</li>
</ol>
在我看来,img src 文件无法解析到正确的位置,因此不会显示。我认为 MEDIA_ROOT 和 MEDIA_SITE 是正确的,其他应用程序的媒体按我的预期工作。
>>> import settings
>>> settings.MEDIA_ROOT
'c:/design.ed/django/media/'
>>> settings.MEDIA_URL
''
这是照片记录模块本身给我的。
>>> from photologue import models as phl
>>> phl.PHOTOLOGUE_DIR
'photologue'
>>> phl.PHOTOLOGUE_PATH
>>> phl.get_storage_path(None, 'foo.jpg')
'photologue\\photos\\foo.jpg'
我在这里缺少什么?
I've installed django-photologue and added a handful of photos to the database. The basic site mechanics seem to be working fine, except no photos or thumbnails are displayed. The images and thumbnails are in ..\django\media\photologue\photos.
For a photo_detail page, the resulting HTML source looks like this:
<title>Greece 3</title>
<h1>Greece 3</h1>
<div class="gallery-photo">
<a href="photologue/photos/greece003.jpg"><img src="photologue/photos/cache/greece003_display.jpg" alt="Greece 3"/></a>
<p>no caption yet</p>
</div>
<h2>This photo is found in the following galleries:</h2>
<ol>
<li>
<a title="Greece 2" href="/photologue/photo/greece-2/"><img src="photologue/photos/cache/greece002_thumbnail.jpg"/></a>
<a href="/photologue/gallery/greece/">LSB Photos - Greece</a>
<a title="Greece 4" href="/photologue/photo/greece-4/"><img src="photologue/photos/cache/greece004_thumbnail.jpg"/></a>
</li>
</ol>
Looks to me like the img src files don't resolve to the right location and therefore don't display. I think MEDIA_ROOT and MEDIA_SITE are correct, and media for other apps work like i expect.
>>> import settings
>>> settings.MEDIA_ROOT
'c:/design.ed/django/media/'
>>> settings.MEDIA_URL
''
And here's what the photologue module itself gives me.
>>> from photologue import models as phl
>>> phl.PHOTOLOGUE_DIR
'photologue'
>>> phl.PHOTOLOGUE_PATH
>>> phl.get_storage_path(None, 'foo.jpg')
'photologue\\photos\\foo.jpg'
What am i missing here?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我想我已经回答了我自己的问题。这个问题与 photologue 没有任何关系:相反,settings.MEDIA_URL 没有正确设置(因为我以前从未通过 Django 实际上提供过任何媒体)。
就我而言,我使用默认的 Django 服务器在本地运行(我知道你不应该在生产中这样做)。所以我在 urls.py 中有这个:
但 MEDIA_URL 是默认的空字符串。相反,我将其更改为
它应该在的位置(在这种情况下,前导斜杠和尾随斜杠都是必需的),并且所有魔法都起作用了。抱歉,由于照片细节使问题变得模糊。
I think i've answered my own question. The problem had nothing whatsoever to do with photologue: rather, settings.MEDIA_URL wasn't set correctly (because i'd never actually served any media through Django before).
In my case, i was running locally using the default Django server (which i know you're not supposed to do for production). So i had this in my urls.py:
but MEDIA_URL was the default empty string. Instead i changed it to
which is where it's supposed to be (both the leading and trailing slashes are required in this case), and all the magic worked. Apologies for clouding the issue with photologue details.