视图.py
def search(request,csv_export):
if request.method == 'POST':
reports = Report.objects.filter(user__in=user_list).order_by('-created_date_time', '-id')
'''''
some code
''''''
if csv_export:
response = HttpResponse(mimetype='text/csv')
filename = "%s-%s.csv" % ('incident-reporter', datetime.datetime.now().strftime('%Y-%m-%d'))
response['Content-Disposition'] = 'attachment; filename=%s' % filename
writer = UnicodeWriter(response, encoding='utf-8')
writer.writerow(headerrow)
for writerow in report_list:
writer.writerow(writerow)
return response
return render(request,'search.html',{'report':report})
网址.py
urlpatterns = patterns(
'incident.views',
(r'^$', 'index'),
(r'^search/$', 'search',{"csv_export": False}),
(r'^csv_export/$', 'csv_export',{"csv_export": True}),
(r'^what/$', 'what'),
(r'^where/$', 'where'),
(r'^when/$', 'when'),
(r'^media/$', 'media'),
)
我收到此错误:
“/report/search/search() 处的 TypeError 恰好需要 2 个参数(给定 1 个)”
请参阅下面的我的回溯:
Traceback:
File "/usr/lib/python2.7/site-packages/django/core/handlers/base.py" in get_response
111. response = callback(request, *callback_args, **callback_kwargs)
File "/usr/lib/python2.7/site-packages/django/contrib/auth/decorators.py" in _wrapped_view
23. return view_func(request, *args, **kwargs)
Exception Type: TypeError at /report/search/
Exception Value: search() takes exactly 2 arguments (1 given)
编辑: urls.py 更新有问题