TypeError:export_users_xls()缺少1个必需的位置参数:'request'
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了TypeError:export_users_xls()缺少1个必需的位置参数:'request'相关的知识,希望对你有一定的参考价值。
当我试图运行时,我得到了这个错误
File "/home/normsoftware/WORK/JVB/healthtracker/quicklook/urls.py", line 39, in <module>
url(r'^users/print$',views.export_users_xls(),name="Exceldata"),
TypeError: export_users_xls() missing 1 required positional argument: 'request'
views.朋友
def export_users_xls(request):
response = HttpResponse(content_type='application/ms-excel')
response['Content-Disposition'] = 'attachment; filename="users.xls"'
wb = xlwt.Workbook(encoding='utf-8')
ws = wb.add_sheet('Users')
# Sheet header, first row
row_num = 0
font_style = xlwt.XFStyle()
font_style.font.bold = True
columns = ['first', 'last',]
for col_num in range(len(columns)):
ws.write(row_num, col_num, columns[col_num], font_style)
# Sheet body, remaining rows
font_style = xlwt.XFStyle()
rows = Registration.objects.all().values_list('first', 'last')
for row in rows:
row_num += 1
for col_num in range(len(row)):
ws.write(row_num, col_num, row[col_num], font_style)
wb.save(response)
return response
所有行缩进都是正确的
URLs.朋友
url(r'^users/print$',views.export_users_xls(),name="Exceldata"),
将您的网址更改为:url(r'^ users / print $',views.export_users_xls,name =“Exceldata”)
如你所见,我没有执行export_users函数(所以删除你的括号),请看这个例子:https://docs.djangoproject.com/en/2.0/topics/http/urls/#example
以上是关于TypeError:export_users_xls()缺少1个必需的位置参数:'request'的主要内容,如果未能解决你的问题,请参考以下文章
TypeError:“TypeError:函数名称不是 HTMLButtonElement.onclick (/:2:54) 处的函数”
反应本机获取多标记[未处理的承诺拒绝:TypeError:TypeError:未定义不是对象(评估'this.state.markers.map
Django TypeError - TypeError: issubclass() arg 1 必须是一个类
pyspark:TypeError:'float'对象不可迭代
Python 3.8 TypeError: can't concat str to bytes - TypeError: a bytes-like object is required, not 's