如何从views.py打印Django表单数据



所以我在Django上运行了一个表单,我试图从views.py打印表单.cleand_data,但它在shell中没有打印任何内容。

$ views.py
from django.http import HttpResponseRedirect
from django.shortcuts import render
from .forms import NameForm
def get_name(request):
# if this is a POST request we need to process the form data
if request.method == 'POST':
# create a form instance and populate it with data from the request:
form = NameForm(request.POST)

# check whether it's valid:
if form.is_valid():
# process the data in form.cleaned_data as required
# ...
print(form.cleaned_data)
# redirect to a new URL:
return HttpResponseRedirect('/polls/thanks/')

# if a GET (or any other method) we'll create a blank form
else:
form = NameForm()
return render(request, 'name.html', {'form': form})
def thanks(request):
return render(request, 'thanks.html')

修复可能很容易——我只是Django的新手。

感谢

您在中犯了一个小的打字错误

cleaned_data

cleanded_data中的d是小写

我把它打印在def谢谢(请求(中,而不是在POST部分中

最新更新