[Django]-Manually calling a class based generic view in Django

43👍

The first way — CategoryTypes.as_view()(self.request) — is right. The problem is that if your view returns a TemplateResponse, its render method isn’t called automatically.

So if you need to access the content of the response, call render() on it first.

1👍

Or you can directly access just content via result.rendered_content. Before making this be sure you will set session into your request before passing into a view:

self.request.session = {}
CategoryTypes.as_view()(self.request)
👤Fusion

Leave a comment