2017-07-11 3 views
0

Warum ist das Formular in Django nicht gültig?

hi ich weiß nicht, warum mein Formular nicht gültig ist! Ich habe versucht, dieseWarum das Formular in Django nicht gültig ist

class SignupForm(forms.Form): 
    first_name = forms.CharField(required=True, max_length=35) 
    last_name = forms.CharField(required=True, max_length=35) 
    username = forms.CharField(required=True, max_length=50) 
    email = forms.EmailField(required=True) 
    password = forms.CharField(required=True, min_length=8, max_length=64) 
    confirm_password = forms.CharField(required=True, min_length=8, max_length=64) 

template.html

<form id="signupForm" action="" method="POST" accept-charset="utf-8" class="form" role="form"> 
    {% csrf_token %} 
    <div class="row"> 
     <div class="col-xs-6 col-md-6"> 
      <input id="first_name" type="text" autocomplete="off" name="firstname" value="" class="form-control input-lg" placeholder="First Name" /> 
     </div> 
     <div class="col-xs-6 col-md-6"> 
      <input id="last_name" type="text" autocomplete="off" name="lastname" value="" class="form-control input-lg" placeholder="Last Name" /> 
     </div> 
    </div> 
    <input id="username" type="text" autocomplete="off" name="username" value="" class="form-control input-lg" placeholder="Choose Username" /> 
    <input id="email" type="text" autocomplete="off" name="email" value="" class="form-control input-lg" placeholder="Your Email" /> 
    <input id="password" type="password" autocomplete="off" name="password" value="" class="form-control input-lg" placeholder="Password" /> 
    <input id="confirm_password" type="password" name="confirm_password" value="" class="form-control input-lg" placeholder="Confirm Password" /> 
    <div class="topmargin active"> 
     <div class="row" style="display: flex;"> 
      <div class="col-xs-5 col-md-5"> 
       <label>I'm </label> 
       <select name="month" class = "form-control input-lg"> 
        <option value="male">Male</option> 
        <option value="female">Female</option> 
       </select> 
      </div> 
      <br /> 
      <span class="help-block">By clicking Create my account, you agree to our Terms and that you have read our Data Use Policy, including our Cookie Use.</span> 
    <button class="btn btn-block signup-btn" type="submit">Create my account</button> 
</form> 

Ich denke, es ist, weil ich das Formular Vorlage passieren nicht, aber ich möchte nicht das tun! es mischt die responsive style befehle sind willkommen danke

+0

Es gibt keine Form Rendering. Du solltest haben. –

+0

Woher wissen Sie, dass es nicht gültig ist? Was ist der Fehler? Und ja, es ist einfacher, das Formular in die Vorlage aufzunehmen. – jgmh

+0

alles was ich weiß ist nur form.is_valid() gibt False zurück @jgmh –

Antwort

2

Die Probleme sind hier perfekt funktionieren:

<input id="first_name" type="text" autocomplete="off" name="firstname" value="" class="form-control input-lg" placeholder="First Name" /> 

<input id="last_name" type="text" autocomplete="off" name="lastname" value="" class="form-control input-lg" placeholder="Last Name" /> 

Sie in Ihrem Formular verwenden Sie first_name und last_name mit Strich, aber bei der Eingabe sind sie ohne die un derscore.

Sie müssen die Eingabenamen ändern, um die Formularfelder entsprechen:

<input id="first_name" type="text" autocomplete="off" name="first_name" value="" class="form-control input-lg" placeholder="First Name" /> 

<input id="last_name" type="text" autocomplete="off" name="last_name" value="" class="form-control input-lg" placeholder="Last Name" /> 
+0

** yup, du hast Recht, das war das Problem, danke ** –

+0

Gern geschehen :) –

-1

ich glaube, ich fand den besten weg zu meiner frage, hier ist es.

in meiner Vorlage i verwendet {{}} form.fieldname insted Tag Eingabe html und für die CSS-Responsivität, verwendet i this sie

+0

Das löst deine Frage nicht wirklich. Sie haben ausdrücklich gesagt, dass Sie Ihr Formular nicht in der Vorlage verwenden möchten (obwohl es die beste Option ist). – jgmh

Verwandte Themen