hundreds-camera-24900
10/29/2021, 9:30 PMwhite-magazine-23424
10/29/2021, 9:31 PMpython
def is_hx_request(request):
return request.META.get("HTTP_HX_REQUEST") == "true"
so, I'm not really breaking a sweat there πwhite-magazine-23424
10/29/2021, 9:32 PMwhite-magazine-23424
10/29/2021, 9:33 PMhundreds-camera-24900
10/29/2021, 9:36 PMhundreds-camera-24900
10/29/2021, 9:36 PMhundreds-camera-24900
10/29/2021, 9:37 PMwhite-magazine-23424
10/29/2021, 9:38 PMhundreds-camera-24900
10/29/2021, 9:39 PMhundreds-camera-24900
10/29/2021, 9:39 PMhundreds-camera-24900
10/29/2021, 9:40 PMwhite-magazine-23424
10/29/2021, 9:42 PMtemplate_name as a kwarg to the Response constructor, drf passes data (first argument to the constructor) as context to the template behind the scenes if the request if for the content type of text/html
So:
python
@api_view
def foo_view(request):
return Response({'message': 'hello!'}, template_name="foo.html")
html
<h1>{{ messgae }}</h1>white-magazine-23424
10/29/2021, 9:43 PMAccept: application/json header, it will return b'{"message": "hello!"}', but if you send a request to the same view with Accept: text/html, it will return b'<h1>hello!</h1>'white-magazine-23424
10/29/2021, 9:44 PMtext/html is the BrowsableAPIRenderer, so actually by default, it would give the whole browsable api UI for text/html requests, but that behavior can be easily changed with settingsbitter-dog-98292
10/29/2021, 11:47 PMmysterious-toddler-20573
10/30/2021, 12:13 AMouterHTML swap?bitter-dog-98292
10/30/2021, 7:41 AMbreezy-army-85649
10/30/2021, 8:14 AMbitter-dog-98292
10/30/2021, 3:00 PMgorgeous-airport-54386
10/30/2021, 4:36 PMfresh-controller-36545
10/30/2021, 7:24 PMwhite-magazine-23424
10/30/2021, 8:08 PMwhite-magazine-23424
10/30/2021, 8:12 PMHx-Request header (i.e., it returns a partial page for htmx and something else for normal requests), and a revamp of the browsable renderer where the something else returned for normal requests is a UI component explorer thing (alongside a BrowsableAPI data view). Everything else in terms of content negotiation, rendering, and the API a library user would interact with is already there in DRF.
So, my vision for the library is just to drop-in a content-negotiator class and a render class that is a UI component explorer; quite minimalcalm-mouse-38665
10/31/2021, 12:58 PMpowerful-ambulance-40990
10/31/2021, 1:30 PMfresh-controller-36545
10/31/2021, 2:35 PMcalm-mouse-38665
10/31/2021, 2:39 PMbest-arm-55473
11/04/2021, 4:11 AMbest-arm-55473
11/04/2021, 4:14 AMextra_js block looked like this:
{% block extra_js %}<script type="module" src="{{tree_populator_js}}"></script>{% endblock extra_js %}
A DOM node (filtered with |json_script) is passed to a function of tree_populator_js. With the tab pattern, can't seem to call the said function anymore. Hoping for tips in the right directionsalmon-xylophone-28580
11/04/2021, 7:20 AM