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
我想将图片名称与此链接分开。
答案 0 :(得分:1)
使用os.path.basename(path)
:返回以字符串形式传递的路径名路径的基本名称。
>> os.path.basename('2012/09/08/4f31063d985c97b64e930917b456083c.jpg')
4f31063d985c97b64e930917b456083c.jpg
详细了解here.