类型错误:export_users_xls()失踪1个人需要的位置参数: '请求'

当我尝试运行我得到这个错误类型错误:export_users_xls()失踪1个人需要的位置参数: '请求'

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"), 

回答:

您的网址改成这样: URL(R '^用户/打印$',views.export_users_xls,NAME = “Exceldata”)

正如你看到的,我没有执行export_users功能(让你删除括号),请参阅此示例: https://docs.djangoproject.com/en/2.0/topics/http/urls/#example

以上是 类型错误:export_users_xls()失踪1个人需要的位置参数: '请求' 的全部内容, 来源链接: utcz.com/qa/263887.html

回到顶部