How do I access the request object in a Django-CMS plugin?

I have a Django-CMS plugin which is used to display a list of objects. The required functionality of the plugin is that the list is paginated and can be re-ordered based on properties of the objects in the list.

Handling this functionality with ajax is not an ideal solution in this particular case so I was planning on using django Paginator, which requires a 'page' querystring parameter, and passing a 'order' querystring parameter which I would then use to define the order of the queryset.

The problem is that I can't see anyway of accessing the request object from within the plugins render function.

Does anyone know if it's possible to access the request object from within the render function, or can suggest a workaround?

Answers


The CMSPluginBase's render method takes a context object. You should be able to access the request via that object if your view is using a RequestContext instance.

class MyCoolPlugin(CMSPluginBase):

    def render(self, context, instance, placeholder):

         #Do something with the request, like access the user
         current_user = context['request'].get('user', None)
         ...

Need Your Help

Can't retrieve the injector from angular

angularjs

I've got this app with two modules:

How to create a code object in python?

python python-3.x bytecode

I'd like to create a new code object with the function types.CodeType() .