Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

427
Vistas
How do you handle a PATCH request from HTMX in Django?

I would like to send a PATCH request to my app but I'm not sure how to consume the request in Django. I am currently getting the following error.

AttributeError: 'WSGIRequest' object has no attribute 'PATCH'

The input field in the HTMX file looks like this (I also made sure to send the CSRF token):

<input 
        name="myfield"
        hx-patch="{% url 'my_update' myobj.id %}"
        hx-swap="none" />

This is the Django View

class MyHtmxView(View):

def patch(self, request, *args, **kwargs):
    form = MyForm(request.PATCH)
    if form.is_valid():
        form.save()
        # return an okay status? 200?
    else:
        return HttpResponse(self.form_invalid(form))

Django is receiving the request, but isn't sure what to do with request.PATCH. I can see in the Django docs that there is a HttpRequest.GET and HttpRequest.POST but no HttpRequest.PATCH https://docs.djangoproject.com/en/3.2/ref/request-response/#httprequest-objects. What's the best way to handle the PATCH?

over 4 years ago · Santiago Trujillo
2 Respuestas
Responde la pregunta

0

You need to parse the request body manually which can be accessed via request.body and parse using QueryDict(request.body)

from django.http.request import QueryDict
 
class MyHtmxView(View):

    def patch(self, request, *args, **kwargs):
        
        # parse request body mannualy
        data = QueryDict(request.body)

        form = MyForm(data)
        if form.is_valid():
            form.save()
            # return an okay status? 200?
        else:
            return HttpResponse(self.form_invalid(form))
over 4 years ago · Santiago Trujillo Denunciar

0

From the docs, your form info will be in the request.POST attribute. You can check for PATCHs with if request.method == "PATCH".

over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda