Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/django/19.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 为什么这个函数有一个类型错误?_Python_Django_Web_Backend - Fatal编程技术网

Python 为什么这个函数有一个类型错误?

Python 为什么这个函数有一个类型错误?,python,django,web,backend,Python,Django,Web,Backend,当我想将订单详细信息打印为PDF文件时,它提供以下信息: 错误: admin_order_pdf() got an unexpected keyword argument 'order' 职能: @staff_member_required def admin_order_pdf(request, order_id): order = get_object_or_404(Order, id=order_id) html = render_to_string('orders/pd

当我想将订单详细信息打印为PDF文件时,它提供以下信息:

错误:

admin_order_pdf() got an unexpected keyword argument 'order'
职能:

@staff_member_required
def admin_order_pdf(request, order_id):
    order = get_object_or_404(Order, id=order_id)
    html = render_to_string('orders/pdf.html', {'order': order})
    response = HttpResponse(content_type='application/pdf')
    response['Content-Disposition'] = f'filename=order_{order.id}.pdf'
    weasyprint.HTML(string=html).write_pdf(response,
                                           stylesheets=[weasyprint.CSS(
                                               settings.STATIC_ROOT + 'css/pdf.css'
                                           )])
    return response
resp = admin_order_pdf(request=req, order_id=123)

您需要接受
order
作为关键字参数:

def admin_order_pdf(request, order):
或者根据函数的要求,将调用代码更改为传递
order\u id

@staff_member_required
def admin_order_pdf(request, order_id):
    order = get_object_or_404(Order, id=order_id)
    html = render_to_string('orders/pdf.html', {'order': order})
    response = HttpResponse(content_type='application/pdf')
    response['Content-Disposition'] = f'filename=order_{order.id}.pdf'
    weasyprint.HTML(string=html).write_pdf(response,
                                           stylesheets=[weasyprint.CSS(
                                               settings.STATIC_ROOT + 'css/pdf.css'
                                           )])
    return response
resp = admin_order_pdf(request=req, order_id=123)

没有
订单
关键字。它是
order\u id
。您没有显示如何调用该函数,因此无法帮助它工作,谢谢:D