![]() ![]() # Overrides the default serve behaviour that normally returns a template response, but we should return Json instead context = self. Return context def serve( self, request, * args, ** kwargs): dataĭef get_context( self, request, * args, ** kwargs):Ĭontext = self. serializer_class:į'serializer_class is not set ') # Custom method that takes the specified serializer defined and returns the pagename and data generated by the serializer to the serve method if not self. ![]() Serializer_class = None # Would normally add e.g "" class Meta:Ībstract = True def get_component_data( self): As of right now I really do feel like using wagtail headlessly is really fighting against my intuition a lot of times when working with pages.īeta Was this translation helpful? Give feedback. However, doing so meant I now had to use JsonResponse(), because the DRF Response() requires the view to be an APIView doing the content negotiation (as far as I understand) which will attach the correct renderer.Īny alternative solutions / ideas / feedback? One of the reasons I wanted to use Response() was simply to allow debug toolbar to work, because I couldn't manage to figure out a middleware allowing that using JsonResponse. The reason being that I prefer not using the PagesAPIViewset and instead going for a route of custom serializers attached to various page models. Since I use wagtail as a headless CMS I ended up overriding the serve method on all page models demonstrated here, rather than using the wagtail API v2: Result = fn( page, request, args, kwargs) route( request, path_components)įor fn in hooks. # we need a valid Site object corresponding to this request in order to proceed site = Site. views api_view() def serve( request, path):
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |