当我试图运行时,我得到了这个错误
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