crudのcreate機能を実装中に詰まってしまいました
発生している問題・エラーメッセージ
Traceback (most recent call last): File "/Users/yoshihiro/.local/share/virtualenvs/mysite-xs0jetOT/lib/python3.8/site-packages/django/core/handlers/exception.py", line 47, in inner response = get_response(request) File "/Users/yoshihiro/.local/share/virtualenvs/mysite-xs0jetOT/lib/python3.8/site-packages/django/core/handlers/base.py", line 179, in _get_response response = wrapped_callback(request, *callback_args, **callback_kwargs) File "/Users/yoshihiro/Desktop/HBGB/mysite/notes/views.py", line 28, in note_create_send form.save() File "/Users/yoshihiro/.local/share/virtualenvs/mysite-xs0jetOT/lib/python3.8/site-packages/django/forms/models.py", line 452, in save raise ValueError( ValueError: The Note could not be created because the data didn't validate.
該当のソースコード
python
1views.py 2from django.shortcuts import render, redirect 3from django.views import generic 4from .models import Note 5from .forms import NoteCreateForm 6 7def note_create(request): 8 context = { 9 'form': NoteCreateForm() 10 } 11 return render(request,'notes/note_create.html', context) 12 13def note_create_send(request): 14 form = NoteCreateForm(request.POST) 15 form.save() 16 return redirect('notes:note_home')
python
1urls.py 2 3from django.urls import path 4from . import views 5 6urlpatterns = [ 7 path('',views.note_home,name='note_home'), 8 path('create',views.note_create,name='note_create'), 9 path('create/send/',views.note_create_send,name='note_create_send'), 10]
python
1forms.py 2 3from django import forms 4from .models import Note 5 6class NoteCreateForm(forms.ModelForm): 7 8 class Meta: 9 model = Note 10 fields = ['title','file','sub','grade','date']
python
1note_create.html 2 3{% block content %} 4<body bgcolor="#00ffff"> 5 <form action="{% url 'notes:note_create_send' %}" method="POST" enctype="multipart/form-data"> 6 {{ form.as_p }} 7 {% csrf_token %} 8 <button type="submit">送信</button> 9 </form> 10</body> 11{% endblock %}
試したこと
ネットで調べてみましたがわかりませんでした
あなたの回答
tips
プレビュー