2014-01-25 50 views
0

views.py独立的图像名称

def index(request): 
    profile = profiles.objects.all() 
    for person in persons: 
     images = profile.image 
     image = 'uploads/no-img.jpg' 
     if images: 
      [x.strip() for x in images.split('/')] 
      image = images[-1:] 
     p = image_name(image = image,activated = 1) 
     p.save() 

models.py

class profiles(models.Model): 
    image = models.ImageField(blank=True,upload_to='%Y/%m/%d') 
    user = models.OneToOneField(User) 

2012/09/08/4f31063d985c97b64e930917b456083c.jpg我想图像名称从这个链接分开。

+2

http://docs.python.org/2/library/os.path.html#os.path.basename –

+0

'ImageFieldFile' 对象有没有属性“RFIND 我得到这个错误,当我这样做。** image = os.path.basename(images)**。 – Thameem

+1

“basename”的参数必须是字符串。 –

回答

1

使用os.path.basename(path):返回作为字符串传递的路径名路径的基名。

>> os.path.basename('2012/09/08/4f31063d985c97b64e930917b456083c.jpg') 
    4f31063d985c97b64e930917b456083c.jpg 

了解更多关于它here.

+0

谢谢。@ santhosh ghimire – Thameem

+0

现在我将图像转换为字符串'str(image)'并得到结果。 – Thameem