Joshua Jonah Joshua Jonah - 5 months ago 39
Python Question

Manually calling a class based generic view

I'm currently trying to call a class based Generic view from within another class based generic view and cant seem to do it correctly.

Ways I've tried:

result = CategoryTypes.as_view() # The same way you put it in the urlconf
print result

<function CategoryTypes at 0x92bd924>

# &


ContentNotRenderedError at /crm/categories/company/
The response content must be rendered before it can be accessed.

result = CategoryTypes().__init__()
print result


How do I call this from another view? I've seriously tried every method on the class and way of calling it I can think of.

Answer Source

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.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download