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 %}
    

      

  • 相关阅读:
    ubuntu18.04更新源
    机器学习网址
    ubuntu18.04下安装Anaconda及numpy、matplotlib
    google云使用记录
    tensorflow省钱方案-ml-engine
    Angular 创建项目
    Angular 环境搭建
    android APP国际化一键切换实现
    android 上下滑动标题栏和状态栏改变颜色实现
    android滑动标题栏渐变实现
  • 原文地址:https://www.cnblogs.com/xzcvblogs/p/11262171.html
Copyright © 2011-2022 走看看