前提・実現したいこと
顧客情報管理システムを作成しています。
今回、顧客詳細画面(custom_detail.html)に
出力ボタンを押下すると画面に出力されているデータをエクセルに出力して
ダウンロードしたいと思っています。
ただ、出力ボタンを押下すると以下のメッセージが出力されます。
Method Not Allowed: /hoge/download/
postしたformの値を受け取る処理がうまく呼び出せていない?と思うのですが
どこを修正すればいいのかが分かりません。
初歩的な質問で申し訳ありませんが、ご教授いただければ幸いです。
html
1<form action="{% url 'talemane:download'%}" method="POST"> 2 {% csrf_token %} 3 <input type="submit" name="submit" value="出力" > 4 </form> 5 <input type="text" readonly class="form-control-plaintext" id="number" value="{{ number }}"> 6 <input type="text" class="form-control" id="last_name" value="{{ last_name }}"> 7 <input type="text" class="form-control" id="first_name" value="{{ first_name }}"> 8 <input type="text" class="form-control" id="last_name_kana" value="{{last_name_kana }}"> 9 <input type="text" class="form-control" id="first_name_kana" value="{{first_name_kana }}"> 10</form>
view
1 2import openpyxl as px 3#... 4 5#ダウンロード処理 6class DateDolwnload(LoginRequiredMixin, generic.ListView): 7 8def post(self, request, *args, **kwargs) : 9 if request.method == "POST": 10 d = { 11 'name':request.GET.get('last_name_kana ') 12 } 13 14 15 if self.request.POST.get('static_employee_number', None): 16 17 wb = px.Workbook() 18 sheet = wb['sheet1'] 19 sheet['C2'] = d ["name"] 20 21 response = HttpResponse(content_type='application/vnd.ms-excel') 22 response['Content-Disposition'] = 'attachment; filename=%s' % 'report.xlsx' 23 24 return render(request, 'hoge/custom_detail_detail.html', {'form': form})
urls
1app_name = 'talemane' 2 urlpatterns = [ 3 #... 4 5 # ダウンロード処理 6 path('download/', DateDolwnload.as_view(), name='download'), 7 ]
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
退会済みユーザー
2019/08/15 23:50
2019/08/16 00:21
退会済みユーザー
2019/08/16 01:00
2019/08/16 01:04