I want to convert the file path to url in django project. How can I convert the file field into url?
Without further configuration, files stored via Django's models.FileField
(also models.ImageField
) end up in your MEDIA_ROOT
folder and will be available under the base path defined by MEDIA_URL
using the folder structure under MEDIA_ROOT
.
Have a look at:
When the configuration is correct, in your template the link to the file is
<a href="{{ object.file.url }}">Download File</a>
If this question is about static files, search for static
and staticfiles
in the Django documentation. It is similar to the media configuration.
EDIT: updated links
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With