i have created a model for image and added in admin. It's uploading images 
fine but when i m trying to display it's generating error this....


Using the URLconf defined in chh.urls, Django tried these URL patterns, in 
this order:

   1. ^admin/

The current URL, photos/photos/DSCN0811.JPG, didn't match any of these.



i have set MEDIA_ROOT= 'C:/chh/photos'

and MEDIA_URL= '/photos/'

in settings.py of this project...... 



models.py is-



from django.db import models
from PIL import Image

class Photo(models.Model):
    photo = models.ImageField(upload_to='photos')
    
    def save(self, size=(200, 200)):
        """
            REQUIRES:
                1.    'from PIL import Image'
            
            DOES:
                1.    check to see if the image needs to be resized
                2.    check how to resize the image based on its aspect 
ratio
                3.    resize the image accordingly
            
            ABOUT:
                based loosely on djangosnippet #688
                http://www.djangosnippets.org/snippets/688/
            
            VERSIONS I'M WORKING WITH:
                Django 1.0
                Python 2.5.1
            
            BY:
                Tanner Netterville
                [email protected]
        """
        
        if not self.id and not self.photo:
            return
        
        super(Photo, self).save()
        
        pw = self.photo.width
        ph = self.photo.height
        nw = size[0]
        nh = size[1]
        
        # only do this if the image needs resizing
        if (pw, ph) != (nw, nh):
            filename = str(self.photo.path)
            image = Image.open(filename)
            pr = float(pw) / float(ph)
            nr = float(nw) / float(nh)
            
            if pr > nr:
                # photo aspect is wider than destination ratio
                tw = int(round(nh * pr))
                image = image.resize((tw, nh), Image.ANTIALIAS)
                l = int(round(( tw - nw ) / 2.0))
                image = image.crop((l, 0, l + nw, nh))
            elif pr < nr:
                # photo aspect is taller than destination ratio
                th = int(round(nw / pr))
                image = image.resize((nw, th), Image.ANTIALIAS)
                t = int(round(( th - nh ) / 2.0))
                print((0, t, nw, t + nh))
                image = image.crop((0, t, nw, t + nh))
            else:
                # photo aspect matches the destination ratio
                image = image.resize(size, Image.ANTIALIAS)
                
            image.save(filename)




plz help me.... i have tried my best but i could not find it....
 

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/django-users?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to