title: Django passing value from template to view
body: <p>I'm having trouble passing values from my template to view. Basically I created a form for user registration, and want to pass the values from the template to view so that I can construct a User object to add to my database. But somehow my "input" is not working when I add <code>name={{user_form.username}}</code>. Also, I want to pass values 0,1,2 respectively when I select "borrower", "libarrian" and "clerk", what can I do to implement this?</p>
  
  <p>Below are my codes.</p>
  
  <pre><code>      &lt;form id="user_form" method="post" action="/sign_up/" class="form-signin" role="form"&gt;
            {% csrf_token %}
          &lt;h2 class="form-signin-heading"&gt;Signup &lt;/h2&gt;
  
              {% if error%}
  
          &lt;div class="error"&gt; Your registration has been unsuccessfull &lt;/div&gt; 
          {% endif %}
  
          &lt;input type="text" class="form-control" name="username" value="{{user_form.username}}" placeholder="Username" required autofocus&gt;
          &lt;input type="password" class="form-control" name="password1" placeholder="Password" value="" required&gt;
          &lt;input type="password" class="form-control" name="password2" placeholder="Retype password" value="" required&gt;       
  
  
          &lt;select class="form-control"&gt;
    &lt;option value="2"&gt;Librarian&lt;/option&gt;
    &lt;option value="0"&gt;Borrower&lt;/option&gt;
    &lt;option value="1"&gt;Clerk&lt;/option&gt;
  &lt;/select&gt;
  
          &lt;button class="btn btn-lg btn-primary btn-block" type="submit"&gt;Sign Up&lt;/button&gt;
  
        &lt;/form&gt;
  </code></pre>
  
  <p>In <strong>forms.py</strong></p>
  
  <pre><code>class UserForm(forms.Form):
      username = forms.CharField(max_length=30)
      password1 = forms.CharField(widget=forms.PasswordInput())
      password2 = forms.CharField(widget=forms.PasswordInput())
  </code></pre>
  
  <p>In <strong>views.py</strong></p>
  
  <pre><code>   def sign_up(request):
      registered = False;
      error = False;
      if request.method == 'POST':
          user_form = UserForm(request.POST)
          if user_form.is_valid():
              registered = True
              username = user_form.cleaned_data['username']
              password = user_form.cleaned_data['password']
              user = User.objects.create_user(username, None, password)
              user.save()
          else:
              error = True;
      else:
          user_form = UserForm()
  
      return render(request, 'books/sign_up.html',
                    {'user_form':user_form,
                     'registered':registered, 'error':error})
  </code></pre>