前提・実現したいこと
djangoで入力フォームを送信するボタンを作りたいです。
発生している問題・エラーメッセージ
cmd
1AttributeError: module 'request' has no attribute 'POST' 2
該当のソースコード
forms
python3
1from django import forms 2from .models import Schedule 3 4 5class SimpleScheduleForm(forms.ModelForm): 6 """シンプルなスケジュール登録用フォーム""" 7 8 class Meta: 9 model = Schedule 10 fields = ('date', 'title', 'word_count', 'evaluation', 'impressions') 11 widgets = { 12 'date': forms.HiddenInput, 13 'title': forms.TextInput(attrs={ 14 'class': 'form-control' }), 15 'word_count': forms.NumberInput, 16 'evaluation': forms.NumberInput, 17 'impressions': forms.TextInput(attrs={ 18 'class': 'form-control'}), 19 } 20 21 def clean(self): 22 self._validate_unique = True 23 return self.cleaned_data
views
python3
1import datetime 2from django.shortcuts import redirect, render 3from django.views import generic 4from .forms import SimpleScheduleForm 5from .models import Schedule 6from . import mixins 7import request 8 9 10class MonthWithScheduleCalendar(mixins.MonthWithScheduleMixin, generic.TemplateView): 11 """スケジュール付きの月間カレンダーを表示するビュー""" 12 template_name = 'month_with_schedule.html' 13 model = Schedule 14 date_field = 'date' 15 16 def get_context_data(self, **kwargs): 17 context = super().get_context_data(**kwargs) 18 calendar_context = self.get_month_calendar() 19 context.update(calendar_context) 20 return context 21 22 form = SimpleScheduleForm(request.POST)
models
python3
1import datetime 2from django.db import models 3 4 5EVALUATION = ( 6 (1, '◎'), 7 (2, '○'), 8 (3, '△'), 9 (4, '×'), 10) 11 12 13class Schedule(models.Model): 14 date = models.DateField('日付') 15 title = models.CharField('タイトル', max_length=100, blank=True) 16 word_count = models.IntegerField('文字数', blank=True) 17 evaluation = models.IntegerField('評価', choices=EVALUATION, blank=True) 18 impressions = models.CharField('感想', max_length=255, blank=True) 19 def __str__(self): 20 return self.word_count
試したこと
pip install requests
補足情報(FW/ツールのバージョンなど)
ubuntu:18.04.3
あなたの回答
tips
プレビュー