2

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?

4

1 回答 1

0

我想我已经回答了我自己的问题。这个问题与 photologue 没有任何关系:相反,settings.MEDIA_URL 设置不正确(因为我以前从未通过 Django 实际提供过任何媒体)。

在我的情况下,我使用默认的 Django 服务器在本地运行(我知道你不应该为生产执行此操作)。所以我在我的 urls.py 中有这个:

(r'^site_media/(?P<path>.*)$', 'django.views.static.serve',
   {'document_root': MEDIA_ROOT, 'show_indexes': True}),

但 MEDIA_URL 是默认的空字符串。相反,我将其更改为

MEDIA_URL = '/site_media/'

这是它应该在的地方(在这种情况下,前导斜杠和尾随斜杠都是必需的),并且所有的魔法都起作用了。很抱歉用照片细节掩盖了这个问题。

于 2011-10-25T23:36:55.320 回答