装饰url后Django-datatable-view抛出错误

时间:2017-10-18 13:18:12

标签: python django django-datatable

我使用django-datable-view来渲染django模型中的数据。

在装饰网址之前一切正常,在我将login_required添加到网址后,它引发了奇怪的错误。 根据该文档,它声明我可以将login_required添加到网址。

以下是我的代码

from django_datatables_view.base_datatable_view import BaseDatatableView

class OrderListJson(BaseDatatableView):
    # The model we're going to show
    model = MyModel

    # define the columns that will be returned
    columns = ['number', 'user', 'state', 'created', 'modified']

    # define column names that will be used in sorting
    # order is important and should be same as order of columns
    # displayed by datatables. For non sortable columns use empty
    # value like ''
    order_columns = ['number', 'user', 'state', '', '']

    # set max limit of records returned, this is used to protect our site if someone tries to attack our site
    # and make it return huge amount of data
    max_display_length = 500

    def render_column(self, row, column):
        # We want to render user as a custom column
        if column == 'user':
            return '{0} {1}'.format(row.customer_firstname, row.customer_lastname)
        else:
            return super(OrderListJson, self).render_column(row, column)

    def filter_queryset(self, qs):
        # use parameters passed in GET request to filter queryset

        # simple example:
        search = self.request.GET.get(u'search[value]', None)
        if search:
            qs = qs.filter(name__istartswith=search)

        # more advanced example using extra parameters
        filter_customer = self.request.GET.get(u'customer', None)

        if filter_customer:
            customer_parts = filter_customer.split(' ')
            qs_params = None
            for part in customer_parts:
                q = Q(customer_firstname__istartswith=part)|Q(customer_lastname__istartswith=part)
                qs_params = qs_params | q if qs_params else q
            qs = qs.filter(qs_params)
        return qs

URL

url(_(r'^users/all/?$'),
    login_required(dashboard.v1.views.OrderListJson.as_view()),
    name='all_users'),

我一直收到错误500,如果我删除login_required,一切正常。如果我能得到关于如何装饰课堂观点的建议,我会很高兴,因为这是我想要实现的目标

0 个答案:

没有答案