当我试图运行时,我收到此错误
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.py
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.py
url(r'^users/print$',views.export_users_xls(),name="Exceldata"),
答案 0 :(得分:0)
将您的网址更改为: url(r&#39; ^ users / print $&#39;,views.export_users_xls,name =&#34; Exceldata&#34;)
如您所见,我没有执行export_users函数(所以删除括号),请参阅以下示例: https://docs.djangoproject.com/en/2.0/topics/http/urls/#example