I'm currently doing a web app that would store files. I have my class lobby like this :
class Lobby(models.Model):
(...)
id = models.UUIDField(primary_key=True, default=uuid.uuid4, help_text="Unique ID for this particular lobby across whole database")
pdf = models.FileField(upload_to='./documents/',blank=True, null=True)
(...)
def file_link(self):
if self.pdf:
return "<a href='%s' download>Download</a>" % (self.pdf.url)
else:
return "No attachment"
file_link.allow_tags = True
file_link.short_description = 'file_link'
(...)
When I'm instanciating a lobby I can easily upload my pdf and it goes to the right place (at the root of my app in file named 'documents').
But here's the problem, when I'm trying to download the file thanks to a link by calling:
<p><strong>File:</strong> {{ lobby.file_link|safe}}</p>
I'm not getting document, but a file not found error
Firefox doesn't find the file http://127.0.0.1:8000/catalog/lobby/73d5aede-96af-445e-bec9-8c4522d37ce7/documents/the document.pdf
It's like the file_link doesn't send the place the file is stored, but the name the url to go to the page a a specific lobby, then the URL.
What did I do wrong??
Thanks.
Edit : worked by adding the enctype='multipart/form-data' attribute of form in HTML.