zoukankan      html  css  js  c++  java
  • Django forms 主要的标签介绍

    修改 forms.py

    from django import forms as DForms
    from django.forms import fields
    from django.forms import widgets
    
    
    class DetailForm(DForms.Form):
        user1 = fields.CharField(widget=widgets.PasswordInput)
        user2 = fields.CharField(widget=widgets.TextInput(attrs={'class': 'c1', 'placeholder': '用户名'}))
        user3 = fields.ChoiceField(choices=[(1, 'SH'), (2, 'BJ'), ])
        user4 = fields.IntegerField()
        user5 = fields.CharField(
            widget=widgets.Select(choices=[(1, 'SH'), (2, 'BJ'),])
        )
        user6 = fields.IntegerField(
            widget=widgets.Select(choices=[(1, 'SH'), (2, 'BJ'), ])
        )
        user7 = fields.IntegerField(
            widget=widgets.RadioSelect(choices=[(1, 'SH'), (2, 'BJ'), ])
        )
    
    

    修改 urls.py

    path('detail.html', views.detail),
    

    修改 views.py

    from django.shortcuts import render, HttpResponse
    from django import forms
    from app01 import forms
    
    
    def detail(request):
        obj = forms.DetailForm(request.POST)
        obj.is_valid()
        print(obj.clean())
    
        return render(request, 'detail.html', {'obj': obj})
    
    

    修改 detail.html

    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <title>Title</title>
    </head>
    <body>
        <form action="detail.html" method="post">
            <div>user1:{{ obj.user1 }}</div>
            <div>user2:{{ obj.user2 }}</div>
            <div>user3:{{ obj.user3 }}</div>
            <div>user4:{{ obj.user4 }}</div>
            <div>user5:{{ obj.user5 }}</div>
            <div>user6:{{ obj.user6 }}</div>
            <div>user7:{{ obj.user7 }}</div>
            <input type="submit" value="提交">
        </form>
    </body>
    </html>
    


  • 相关阅读:
    php gettext 注释
    autobench 测试笔记
    Android 常用布局视图
    路由器插入广告实现
    kafka 搭建与使用
    复制虚拟机之后,互相ping不通
    docker运行镜像提醒WARNING: IPv4 forwarding is disabled. Networking will not work.
    docker容器简单常用操作
    mongo通过URL连接IDEA
    gradle基础应用
  • 原文地址:https://www.cnblogs.com/klvchen/p/11230678.html
Copyright © 2011-2022 走看看