[Answer]-Django passing value from template to view

1👍

Below form should work.

<form id="user_form" method="post" action="/sign_up/" class="form-signin" role="form">
    {% csrf_token %}
    <h2 class="form-signin-heading">Signup </h2>
    <input type="text" class="form-control" name="username"  value="{{user_form.username}}" placeholder="Username" required autofocus>
    <input type="password" class="form-control" name="password1" placeholder="Password" required>
    <input type="password" class="form-control" name="password2" placeholder="Retype password" required>      
    <select class="form-control">
        <option value="1">Librarian</option>
        <option value="0">Borrower</option>
        <option value="2">Clerk</option>
    </select>
    <button class="btn btn-lg btn-primary btn-block" type="submit">Sign Up</button>
</form>

Changes I have done are –

  1. Change the names of username and password textboxes
  2. Change the type for username textbox
  3. Added value attribute in select control

Leave a comment