Given that I am a "wet behind the ears" newbie, maybe I should not be
attempting this, but... I need some simple and straightforward guidance on
uploading and using images in a simple database application, which (so far)
only uses the admin interface.
I working on my development machine (i.e. no Apache integration as yet).
The use case is not that complex. If I have an "Event" object, with which I
want to associate a number of images (typically, photos taken by people at
that event), then I also need an "EventImage" object, with the event.id as
the foreign key.
So, the models look like:
class Event(models.Model):
id = models.AutoField(primary_key=True)
date_time = models.DateTimeField()
title = models.CharField(unique=True,max_length=250)
class EventImage(models.Model):
id = models.AutoField(primary_key=True)
caption = models.CharField(unique=True,max_length=10)
title = models.CharField(max_length=250)
event = models.ForeignKey(Event)
image = models.ImageField(upload_to='photos')
What I have gathered so far, from browsing articles and snippets and Q&A, is
that I also need:
1.to add/change settings.py:
MEDIA_ROOT = '/home/blah/blah/mysite/media/'
MEDIA_URL = 'http://127.0.0.1:8000/media/'
ADMIN_MEDIA_PREFIX = '/media/'
STATIC_DOC_ROOT = '/home/blah/blah/mysite/media/'
2. add the following to the start of urls.py:
from django.conf import settings
3. add the following to the end of urls.py:
if settings.DEBUG:
urlpatterns += patterns('',
(r'^static/(?P<path>.*)$', 'django.views.static.serve',
{'document_root': settings.STATIC_DOC_ROOT}),
)
(I have also tried variations on the above, such as:
(r'^media/(?P<path>.*)$', 'django.views.static.serve',
and
(r'%s(?P<path>.*)' % settings.MEDIA_URL[1:],
'django.views.static.serve',
{'document_root': settings.MEDIA_ROOT}),
)
but in all cases, although the file does get uploaded and appears in the
'/home/blah/blah/mysite/media/photos/' directory, when I click on the link -
which is shown as
http://127.0.0.1:8000/media/photos/test.jpg
I get a "Page not found: /media/photos/test.jpg"
This seems like a simple thing to fix - but not for me?
Any help to fix this is appreciated, as is any guidance on what will need to
change once this project needs to run under Apache...
Thanks
Derek
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---