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

刪除'urls.py'中'views.export_users_xls()'中的圓括號。 –

回答

相關問題