I can succesfully save a file via Django admin in one of my models but cannot open the file aftewards. Here is my model:
class Answer (models.Model):
answer = models.CharField(max_length=1000)
attach_file = models.FileField(upload_to='Attachments', blank=True)
I have not touched the settings file and to my understanding it should use defaults values:
MEDIA_ROOT = ''
MEDIA_URL = ''
STATIC_ROOT = ''
I registered the model in the admin.py and I was able to Browse a file and save it. When trying to open that file, i get:
Page not found (404)
Request Method: GET
Request URL: http://127.0.0.1:8000/admin/businessui/answer/1/Attachments/outlook.png/
answer object with primary key u'1/Attachments/outlook.png' does not exist.
Could someone point out what I am missing here to be able to also open saved files locally on my dev machine?
In reference to @Sawwy’s comment on @RicardoCarmo’s answer. I post as an answer for the formatting.
Here’s what I use in my main url conf:
Note that in a production environment, your media files should be served up by the web server and those requests should not reach Django. That is why it’s qualified with
if DEBUG or DEBUG_MEDIA.