Hacker News new | ask | show | jobs
by rojoca 1665 days ago
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.