How to receive a PDF file in Django and save to a directory?

0

I get a file by html using type="file".

<form action="/docs/enviado/" method="post">{% csrf_token %}
  <input type="file" accept="pdf" name = "projeto"/><br /><br />
  <input type="submit" value="enviar" />
</form>

But I can not save using python, I tried that but it did not work:

projeto = request.POST.get('projeto')
projeto.save

And so:

projeto = request.FILES["projeto"]
projeto.save

I just need to get the pdf file and save it to the directory that already exists.

    
asked by anonymous 20.10.2016 / 20:43

1 answer

0

In your form

<form action="/docs/enviado/" method="post" enctype="multipart/form-data">

In your field in the model:

meuarquivo = models.FileField(upload_to='meusarquivos/')

In your view

form = MeuForm(request.POST, request.FILES)
    
21.10.2016 / 18:50