Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to return an HttpResponse object in render function?

Reasons for why someone would want to do this aside, is it possible? Something along the lines of

from cms.plugin_base import CMSPluginBase
from data_viewer.models.data_view import DataPlugin
from django.http import HttpResponse

    class CMSPlugin(CMSPluginBase):

        def render(self, context, instance)
            response = HttpResponse(content_type='text/csv')
            return response

Usually render functions require a context to be returned, thus this code doesn't work as is. Once again, I know this isn't typical. I just want to know if it's possible

Thanks in advance, all help is appreciated!

like image 889
Greg Avatar asked Jun 11 '26 08:06

Greg


1 Answers

In short: No.

The render method is very unfortunately named and should really be called get_context. It must return a dictionary or Context instance, see the docs

If you want to extend django CMS with something that returns HttpResponse objects, have a look at apphooks.

like image 191
ojii Avatar answered Jun 12 '26 22:06

ojii



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!