Friday, 15 January 2010

Django Error Page not found (404) -



Django Error Page not found (404) -

i'm been working on photo organizer , sharing app part @ http://lightbird.net/dbe/photo.html. i'm trying add together image , when . error.

page not found (404) request method: request url: http://donkey123.pythonanywhere.com/admin/photo/image/1/images/penguins_7.jpg/ image object primary key u'1/images/penguins_7.jpg' not exist. you're seeing error because have debug = true in django settings file. alter false, , django display standard 404 page.

my models

from django.db import models django.contrib.auth.models import user django.contrib import admin string import bring together import os pil import image pimage mysite.settings import media_root class album(models.model): title = models.charfield(max_length=60) public = models.booleanfield(default=false) def __unicode__(self): homecoming self.title class tag(models.model): tag = models.charfield(max_length=50) def __unicode__(self): homecoming self.tag class image(models.model): title = models.charfield(max_length=60, blank=true, null=true) image = models.filefield(upload_to="images/") tags = models.manytomanyfield(tag, blank=true) albums = models.manytomanyfield(album, blank=true) created = models.datetimefield(auto_now_add=true) rating = models.integerfield(default=50) width = models.integerfield(blank=true, null=true) height = models.integerfield(blank=true, null=true) user = models.foreignkey(user, null=true, blank=true) def __unicode__(self): homecoming self.image.name def save(self, *args, **kwargs): """save image dimensions.""" super(image, self).save(*args, **kwargs) im = pimage.open(os.path.join(media_root, self.image.name)) self.width, self.height = im.size super(image, self).save(*args, ** kwargs) def size(self): """image size.""" homecoming "%s x %s" % (self.width, self.height) def __unicode__(self): homecoming self.image.name def tags_(self): lst = [x[1] x in self.tags.values_list()] homecoming str(join(lst, ', ')) def albums_(self): lst = [x[1] x in self.albums.values_list()] homecoming str(join(lst, ', ')) def thumbnail(self): homecoming """<a href="/media/%s"><img border="0" alt="" src="/media/%s" height="40" /></a>""" % ( (self.image.name, self.image.name)) thumbnail.allow_tags = true class albumadmin(admin.modeladmin): search_fields = ["title"] list_display = ["title"] class tagadmin(admin.modeladmin): list_display = ["tag"] class imageadmin(admin.modeladmin): search_fields = ["title"] list_display = ["__unicode__", "title", "user", "rating", "size", "tags_", "albums_","thumbnail","created"] list_filter = ["tags", "albums","user"] def save_model(self, request, obj, form, change): obj.user = request.user obj.save()

i think models,py fine think problem lay @ media_root= , media url=

my media_root = '/home/donkey123/mysite/photo'

and media_url "" blank.

i don't know set media_url problem.

thanks in advance

in model (note there no need slash @ end):

image = models.filefield(upload_to="images")

that means these images go in {media folder}/images/

in settings.py:

media_root = os.path.join(os.path.dirname(__file__), '../../web/media').replace('\\','/')

that means media folder is: project_root/web/media

so images model go in: project_root/web/media/images

the stuffs above define images saved on filesystems. want define accessed via http.

in settings.py define url pointing media folder:

media_url = '/media/'

then images model in:

http://my-url/media/images/image_name.jpg

tests these settings without model/library first 1 image. read following:

to reply specific questions:

my media_root = '/home/donkey123/mystic/photo' => see example, media_root should relative settings.py file work when going live, on dev machine, etc.

and media_url= "" blank. => should '/media/' because in model doing this:

def thumbnail(self): homecoming """<a href="/media/%s">

hope helps

django

No comments:

Post a Comment