# views.pyfrom django.http import HttpResponseRedirectfrom django.shortcuts import renderfrom .forms import NameFormdef get_name(request):# if this is a POST request we need to process the form dataif 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# ...# redirect to a new URL:return HttpResponseRedirect('/thanks/')# if a GET (or any other method) we'll create a blank formelse:form = NameForm()return render(request, 'name.html', {'form': form})
# name.html<form action="/your-name/" method="post">{% csrf_token %}{{ form }}<input type="submit" value="Submit"></form>
更改查询集
