django-photologue constructs the wrong URLs for photos

956 views Asked by At

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?

1

There are 1 answers

0
SeanB On

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:

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

but MEDIA_URL was the default empty string. Instead i changed it to

MEDIA_URL = '/site_media/'

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.