How to get the link of the file in a FileField? How to get the link of the file in a FileField? django django

How to get the link of the file in a FileField?


The output is based on your settings file, have a look here for an understanding on serving staticfiles in development and/or production:

Confusion in Django admin, static and media files


I'm guessing you have the field defined as:

picture = models.ImageField(upload_to="/home/xxx/media/files/reference")

in other words is it possible you have defined an absolute path for the upload_path property of the field ?

Try something like

from django.conf import settingspicture = models.ImageField(upload_to=settings.MEDIA_ROOT + "files/reference")