标签:
1、django.admin.py startproject cs3
cd cs3
django.admin.py startapp blog
2、 vim urls.py
url(r‘^regist/$‘,‘blog.views.regist‘), 注册
url(r‘^login/$‘,‘blog.views.login‘), 登录
url(r‘^index/$‘,‘blog.views.index‘), 跳转界面
url(r‘^logout/$‘,‘blog.views.logout‘), 注销
)
3、vim blog/views.py
from django import forms
from django.http import HttpResponse
from django.shortcuts import render_to_response
from models import User
class UserForm(forms.Form):
username = forms.CharField()
password = forms.CharField(widget=forms.PasswordInput)
def regist(req):
if req.method == "POST":
uf = UserForm(req.POST)
if uf.is_valid():
username = uf.cleaned_data[‘username‘]
password = uf.cleaned_data[‘password‘]
User.objects.create(username=username,password=password)
return HttpResponse(‘ok‘)
else:
uf = UserForm
return render_to_response(‘regist.html‘,{‘uf‘:uf})
4、vim blog/templates/regist.html
<form method="post">
{{uf.as_p}}
<input type="submit" value=‘nice‘/ >
</form>
5、 python syncdb
python manage.py runserver
标签:
原文地址:http://www.cnblogs.com/Icanflyssj/p/5134650.html