使用Django表单点击“提交”按钮时我没有数据
from django.shortcuts import render, get_object_or_404
from django.http import Http404
from .forms import BlogPostForm
from .models import BlogPost
def blog_post_list_view(request):
qs = BlogPost.objects.all()
template_name = 'blog/list.html'
context = {'object_list': qs}
return render(request, template_name, context)
def blog_post_create_view(request):
template_name = 'form.html'
form = BlogPostForm(request.POST or None)
if form.is_valid():
print(form.cleaned_data)
context = {'form': form}
return render(request, template_name, context)
这是forms.py 从Django导入表单中获取
class BlogPostForm(forms.Form):
title = forms.CharField()
slug = forms.SlugField()
content = forms.CharField(widget=forms.Textarea)
我希望输入的数据可以在控制台上打印出来,以便查看是否可以保存数据