创建一个1.html的东西
<html>
<body>
<form method='post'>
{{form.as_p}}
<input type="submit" name="ok" />
</form>
</body>
</html>
创建并写一个form.py
from django import forms
class Mybook(forms.Form):
name=forms.CharField()
author=forms.CharField()
date=forms.CharField()
修改views
from django.shortcuts import render
from django.shortcuts import render_to_response
from django.forms import *
from django.http import HttpResponse
from myapp.models import *
def hello(request):
if request.method == 'post':
form=Mybook(request.POST)
if form.is_valid():
data=form.cleaned_data
title=data['title']
return HttpResponse(title)
form=Mybook()
return render_to_response('1.html',{'form':form})
修改urls.py
from django.conf.urls import patterns, include, url
from django.contrib import admin
from myapp.views import *
urlpatterns = patterns('',
# Examples:
# url(r'^$', 'myproj.views.home', name='home'),
# url(r'^blog/', include('blog.urls')),
url(r'^admin/', include(admin.site.urls)),
(r'^hello/$',hello)
)