I don't know this is a typical thing to do in web application, but what we achieve is that, let's say we have a Person model, inside this model, we have a FileField
stores user's photo:
class Person(models.Model):
photo = models.FileField(upload_to='Person_photo')
What I want to achieve is that only the owner can see his or her photo. People who log on a different account or even not log in should not be able to see the photo. Let's assume we have a way to check whether a photo belongs to a certain user or not:
def permission(photo_filename, pid):
# return True if photo_filename exists and belongs to the person pid
We can figure this part out, for example, use permission system provided in Django. Of course from the views.py
we can control whatever image we want to show on the page, but for example, we want to block people make attempts to figure out the URLs and get the photo, for example, typing
http://some.domain/media/Person_photo/Amy.jpg
in URL bar in the browser should only work if she is Amy. What is a good way to do it? Is there a library for this purpose?