Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Haven't used django for a year or 2 but used to use django-rest-framework's negotiation to get both json and html responses (was using inertiajs not htmx) and it worked pretty well. You can use decorators on the api methods to set things like templates. Here's an example:

  @inertia("User/List")
  @api_view(["GET"])
  def get_users(request,  **kwargs):
    // ...
    return Response(data={"users": users})
This can return JSON or HTML with the data injected.


Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: