Changes between Initial Version and Version 1 of Ticket #32991, comment 6
- Timestamp:
- Aug 5, 2021, 8:57:18 PM (3 years ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
Ticket #32991, comment 6
initial v1 3 3 The other use case to consider is when uploading files for consumption by the web application. After the files have been uploaded, the application has a need to find a relative path to the uploaded file via a model. And Django FAQ documentation actually describes how to achieve this https://docs.djangoproject.com/en/3.2/faq/usage/#how-do-i-use-image-and-file-fields: 4 4 > All that will be stored in your database is a path to the file (relative to MEDIA_ROOT). You’ll most likely want to use the convenience url attribute provided by Django 5 What is returned by `.url` attribute is also a relative path to the file, which the application can then access via the FileField on the model. If there is no static content being served, then `MEDIA_URL` will not be set . This is the use case and the setup used in our application. We are not using Django templates or serving any static content. In our application there are only a few places where `.url` attribute is being used, so it is a simple change for us. There are other attributes provided by FileField that can be used in lieu of `.url`.5 What is returned by `.url` attribute is also a relative path to the file, which the application can then access via the FileField on the model. If there is no static content being served, then `MEDIA_URL` will not be set (most likely). This is the use case and the setup used in our application. We are not using Django templates or serving any static content. In our application there are only a few places where `.url` attribute is being used, so it is a simple change for us. There are other attributes provided by FileField that can be used in lieu of `.url`.