码迷,mamicode.com
首页 > 其他好文 > 详细

django 学习-15 Django会话Cookie

时间:2016-01-15 23:13:23      阅读:364      评论:0      收藏:0      [点我收藏+]

标签:

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

django 学习-15 Django会话Cookie

标签:

原文地址:http://www.cnblogs.com/Icanflyssj/p/5134650.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!