Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

193
Visualizações
Python Django - Uploading a file from the shell

I am trying to upload a file from a shell to one of my django models in the following manner:

a = Post(name=name, content=content)
a.attachment.save('some.pdf', File(open('some.pdf', 'r')))        

But I keep getting the following error: TypeError: must be convertible to a buffer, not FieldFile. I looked at other posts and could not find any solution that solves this problem.

I am using Python 2.7 and Django 1.10. I would really appreciate any help.

EDIT: The problem was not with the way I was storing the file but was with my post-save signals. Sorry and thanks for your help!

over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

try:

f = open('some.pdf', 'r')
a.attachment = File(f)
a.save()
f.close()
over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda