Skip to content

Comment on Django REST framework 3.15.0

Comments

I like the automatic model serializers, but don't like the extra layer of syntax in views, ie different than normal Django. DRF's system can be replaced in many cases by these helper functions:

  def return_json(msg: dict) -> HttpResponse:
      return HttpResponse(json.dumps(msg), content_type="application/json")

  def load_body(request: HttpRequest) -> dict:
    return json.loads(request.body.decode("utf-8"))
This avoids the cognitive overhead of layering another syntax on top of Django's own conventions.

Apparently; even better; ty!

Edit: Did a drop-in replacement of JsonResponse; confirmed working.

AboutSource Built by g1lg1l

Hackerly is an independent reader for Hacker News, built on the public HN API. Not affiliated with Y Combinator.