zoukankan      html  css  js  c++  java
  • django的from组件

    1.后端
    from django import froms from django import forms from app import models class RegForm(forms.Form): username=forms.CharField(max_length=8,min_length=3,label='用户名', error_messages={ 'max_length':'用户名最长八位', 'min_length':'用户名最短三位', 'required':'用户名不能为空', },widget=forms.widgets.TextInput(attrs={'class':'form-control'})) password=forms.CharField(max_length=8,min_length=3,label="密码", error_messages={ 'max_length':'密码最长八位', 'min_length':'密码最短三位', 'required':'密码不能为空' },widget=forms.widgets.PasswordInput(attrs={'class':'form-control'})) confirm_password = forms.CharField(max_length=8, min_length=3, label="确认密码", error_messages={ 'max_length': '密码最长八位', 'min_length': '密码最短三位', 'required': '密码不能为空' }, widget=forms.widgets.PasswordInput(attrs={'class':'form-control'})) email=forms.EmailField(label='邮箱',error_messages={ 'lnvalid':'邮箱格式错误', 'required':'邮箱不能为空', },widget=forms.widgets.EmailInput(attrs={'class':'form-control'})) def clean_username(self): username=self.cleaned_data.get('username') user_obj=models.Userinfo.objects.filter(username=username).first() if user_obj: self.add_error('username','用户名已存在') else: return username def clean(self): password=self.cleaned_data.get('password') confir_password=self.cleaned_data.get('confirm_password') if not password == confir_password: self.add_error('confirm_password','两次密码不一致') else: return self.cleaned_data

     2 前端渲染

    {% for foo in  form_obj%}
                            <div class="form-group">
                            <label for="{{ foo.auto_id }}">{{ foo.label }}</label>
                                {{ foo }}
                                 <span></span>
                            </div>
                        {% endfor %}
    

      

  • 相关阅读:
    Top 10 Product Manager Skills To Boost Your Resume In 2021
    大数据知识梳理
    B端产品如何设计权限系统?
    华三盒式交换机MAC、ARP、Route性能表项参数查询
    中了传说中的挖矿病毒
    SqlServer 2019 事务日志传送
    docker中生成的pdf中文是方框的解决方案
    The Live Editor is unable to run in the current system configuration
    2021 面试题大纲
    五分钟搞定Docker安装ElasticSearch
  • 原文地址:https://www.cnblogs.com/xzcvblogs/p/11262171.html
Copyright © 2011-2022 走看看