zoukankan      html  css  js  c++  java
  • django notes 七:Using Forms

    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>
  • 相关阅读:
    001 Python网络爬虫与信息提取 课程前序
    004 JQuery (010
    Vuex的元素对象
    003 JQuery (009
    002 JQuery (004
    001 JQuery (001
    Vuex简介
    axios实例与模块封装
    axios拦截器
    015 Javascript(152
  • 原文地址:https://www.cnblogs.com/lesliefang/p/4725125.html
Copyright © 2011-2022 走看看