4

I want to convert the file path to url in django project. How can I convert the file field into url?

naveen
  • 71
  • 1
  • 5
  • 1
    There's not nearly enough detail here. What file path? What URL do you want to end up with? What relationship would a file path have with a URL? – Daniel Roseman Apr 06 '16 at 09:27

1 Answers1

5

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

Risadinha
  • 16,058
  • 2
  • 88
  • 91