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

221
Views
¿Qué formato de archivo requiere django imagefield (filefield)?

Uso django-rest-framework por primera vez. Yo uso el formato json por defecto. Necesito enviar un archivo para crear una nueva instancia. Este archivo se ha guardado en models.ImageField. Sin embargo, no sé qué formato requiere este campo para el archivo entrante. Intenté enviarlo en base64, pero no es adecuado.

TestCase para este problema:

 class PersonTestCase(APITestCase): def setUp(self): self.c = APIClient() def test_sign_up_with_valid_data(self): with open('persons/test/bg.jpg', 'rb') as bg: valid_registration_data = { ..., 'background': base64.b64encode(bg.read()).decode('utf-8'), } response = self.c.post('/persons/sign_up', valid_registration_data) self.assertEqual(response.status_code, 201) self.assertEqual(Person.objects.count(), 1) self.assertEqual(Person.objects.get('username'), 'test_client74562984')

Vista:

 class SignUpView(APIView): """ Create new user """ def post(self, request): serializer = UserSerializer(data=request.data) if serializer.is_valid(): serializer.save() response = Response(serializer.data, status=status.HTTP_201_CREATED) return response response = Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST) return response
over 4 years ago · Santiago Trujillo
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!