###状況
Djangoでwebアプリを作っています。
views.pyのdefを直接呼び出した場合はうまくいくのですが、
上記のdefをclassに入れ、urls.pyのas_view()で呼び出した場合に
TypeError 'NoneType' object is not callableエラーが出ます。
###質問
インデントが違うのでしょうか?
return responseについてよく分かっておらず
解決策がございましたらご教示ください。
view
1# classの場合 2class AccountExportView(LoginRequiredMixin, generic.FormView): 3 template_name = 'app/export.html' 4 def export(request): 5 response = HttpResponse(content_type='text/csv; charset=Shift-JIS') 6 response['Content-Disposition'] = 'attachment; filename=account.csv' 7 df = pd.DataFrame(list(Account.objects.filter(updateflag='1').values()), 8 columns=['userid', 'employeenumber', 'lastname', 'firstname', 'password']) 9 df.to_csv(path_or_buf=response,encoding='cp932',sep=',',float_format='%.2f',index=False,decimal=".") 10 return response 11
view
1# classを作らずdefのみの場合 2def export(request): 3 response = HttpResponse(content_type='text/csv; charset=Shift-JIS') 4 response['Content-Disposition'] = 'attachment; 5 filename=account.csv' 6 df = pd.DataFrame(list(Account.objects.filter(updateflag='1').values()), 7 columns=['userid', 'employeenumber', 'lastname', 'firstname', 'password']) 8 df.to_csv(path_or_buf=response,encoding='cp932',sep=',',float_format='%.2f',index=False,decimal=".") 9 return response
urls
1# classの場合 2from .views import AccountExportView 3app_name = 'app' 4 5urlpatterns = [ 6 path('export', views.AccountExportView.as_view(), name='export'), 7]
urls
1# defのみの場合 2from .views import AccountExportView 3app_name = 'app' 4 5urlpatterns = [ 6 path('export', views.export, name='export'), 7]
error
1TypeError at /app/export 2'NoneType' object is not callable 3Request Method: GET 4Django Version: 2.2 5Exception Type: TypeError 6Exception Value: 7'NoneType' object is not callable
あなたの回答
tips
プレビュー