<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                企業??AI智能體構建引擎,智能編排和調試,一鍵部署,支持知識庫和私有化部署方案 廣告
                >[success] # 講解 >[danger] ##### 常用的引入 ~~~ 1.from django.forms import Form 2.from django.forms import fields 3.from django.forms import widgets 4.from django.core.validators import RegexValidator 5.from cm import models 6.from django.core.exceptions import ValidationError ~~~ * 翻譯 ~~~ 1. 繼承Form 實例庫 2. 繼承form 驗證字段 3. 使用input 插件 4. 正則表達式驗證 5. 數據庫的引入 6. 返回的錯誤提示 ~~~ >[danger] ##### 單個字段使用的實例 ~~~ username = fields.CharField( max_length=32, widget=widgets.TextInput(attrs={"class":"username form-control"}), validators=[RegexValidator(r'^[a-zA-Z0-9_-]{4,16}$','4到16位(字母,數字,下劃線,減號)')], error_messages={"required":"不能為空"} ) ~~~ >[danger] ##### clean_字段 用法 ~~~ def clean_email(self): v = self.cleaned_data['email'] user_obj = models.UserInfo.objects.filter(email=v).count() if user_obj: raise ValidationError("郵箱存在") return v ~~~ >[danger] ##### clean 用法 ~~~ def clean(self): value_dict = self.cleaned_data password = value_dict.get("password") confirm_password = value_dict.get("confirm_password") if password != confirm_password: raise ValidationError("密碼不一致") return value_dict ~~~ >[success] # 整體代碼 ~~~ from django.forms import Form from django.forms import fields from django.forms import widgets from django.core.validators import RegexValidator from cm import models from django.core.exceptions import ValidationError class RegisterForm(Form): def __init__(self,request,*args,**kwargs): self.request = request super(RegisterForm,self).__init__(*args,**kwargs) username = fields.CharField( max_length=32, widget=widgets.TextInput(attrs={"class":"username form-control"}), validators=[RegexValidator(r'^[a-zA-Z0-9_-]{4,16}$','4到16位(字母,數字,下劃線,減號)')], error_messages={"required":"不能為空"} ) nickname = fields.CharField( max_length=32, widget=widgets.TextInput(attrs={"class":"nickname form-control"}), validators=[RegexValidator(r'^[a-zA-Z0-9_-]{4,16}$','4到16位(字母,數字,下劃線,減號)')], error_messages={"required":"不能為空"} ) password = fields.CharField( max_length=64, widget = widgets.TextInput(attrs={"class":"password form-control"}), validators=[RegexValidator(r'^[a-zA-Z0-9_-]{4,16}$', '4到16位(字母,數字,下劃線,減號)')], error_messages={"required": "不能為空"} ) confirm_password = fields.CharField( max_length=64, widget=widgets.TextInput(attrs={"class":"confirm_password form-control"}), validators=[RegexValidator(r'^[a-zA-Z0-9_-]{4,16}$', '4到16位(字母,數字,下劃線,減號)')], error_messages={"required": "不能為空"} ) email = fields.EmailField( error_messages={"required":"不能為空", "invalid": "郵箱格式錯誤"}, widget=widgets.TextInput(attrs={"class":"nickname form-control"}) ) check_code = fields.CharField( max_length=4, error_messages={"required": "驗證碼不能為空", "max_length": "請輸入正確驗證碼"} ) def clean_username(self): v = self.cleaned_data['username'] user_obj = models.UserInfo.objects.filter(username=v).count() if user_obj: raise ValidationError("昵稱已被注冊") return v def clean_email(self): v = self.cleaned_data['email'] user_obj = models.UserInfo.objects.filter(email=v).count() if user_obj: raise ValidationError("郵箱存在") return v def clean_check_code(self): v = self.cleaned_data['check_code'] if self.request.session.get('CheckCode').upper() != v.upper(): raise ValidationError("驗證碼錯誤") return v def clean(self): value_dict = self.cleaned_data password = value_dict.get("password") confirm_password = value_dict.get("confirm_password") if password != confirm_password: raise ValidationError("密碼不一致") return value_dict ~~~
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看