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

django notes 七:Using Forms

时间:2015-08-12 19:16:57      阅读:93      评论:0      收藏:0      [点我收藏+]

标签:

form 也没什么可说的,我只给一个例子大家就懂了

form model

from django import forms


class UserForm(forms.Form):
    username = forms.CharField(label=UserName, max_length=100)
    password = forms.CharField(label=Password, max_length=20, widget=forms.PasswordInput())

views.py

def login(request):
    if request.method == POST:
        form = UserForm(request.POST)

        print form.data[username]
        print form.data[password]

        if form.is_valid():
            return HttpResponse(content=submit ok)

        return render(request, polls/name.html, {form: form})
    else:
        form = UserForm()
        return render(request, polls/name.html, {form: form})

模板

<form action="/polls/login/" method="post">
    {% csrf_token %}
    {{ form }}

    <input type="submit" value="Submit"/>
</form>

 

django notes 七:Using Forms

标签:

原文地址:http://www.cnblogs.com/lesliefang/p/4725125.html

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