Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

248
Views
Obtener 'str' en formularios de Djano.FileField()

Estoy cargando sin un formulario. Mi usuario tiene un FileField si estoy cargando a través <input type...> no tengo ningún problema. Pero esto no es tan útil para mi propósito.

vistas.py

 def uploadaction2(request): f = forms.FileField() # this is my idea data = json.loads(request.body) # f.clean("data['data']") # error: file_name = data.name AttributeError: 'str' object has no attribute 'name' logger.error(type(data['data'])) #gives <class 'str'> and without the type the string that i want to save with open('newfile', 'w') as file: file.write(data['data']) request.user.file = file request.user.save() # i get no error until this part

Error

 Internal Server Error: .... in pre_save if file and not file._committed: AttributeError: '_io.TextIOWrapper' object has no attribute '_committed'

Creo que tengo que convertir la cadena json en un formulario.FileField() porque no tengo idea de cómo se podría hacer esto.

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

 def uploadaction2(request): file = request.FILES.get('file') # set name to input request.user.file = file request.user.save()
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!