如何在Django-CMS插件中访问请求对象?

Eri*_*ler 14 django plugins paginator request django-cms

我有一个Django-CMS插件,用于显示对象列表.插件所需的功能是列表是分页的,可以根据列表中对象的属性重新排序.

在这种特殊情况下使用ajax处理这个功能并不是一个理想的解决方案,因此我计划使用django Paginator,它需要一个'page'查询字符串参数,并传递一个'order'查询字符串参数,我将用它来定义顺序查询集.

问题是我无法看到从插件渲染功能中访问请求对象.

有谁知道是否可以从渲染功能中访问请求对象,或者可以建议一个解决方法?

Cas*_*sey 23

CMSPluginBase的render方法接受上下文对象.如果您的视图使用RequestContext实例,则应该能够通过该对象访问请求.

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)
         ...
Run Code Online (Sandbox Code Playgroud)