title: name 'user' is not defined
body: <p>I'm trying to make a custom registration page without using usercreationform i've made the model and imported it but when i run it I keep encountering this error
  NameError at /register
  name 'user' is not defined
  the line in particular is:<br />
  if user.password != user.repassword:</p>
  <p>and i tried changing the method to GET instead of POST and i got a different error MultiValueDictKeyError 'fname'</p>
  <p>views.py</p>
  <pre><code>from django.shortcuts import render,redirect
  from .models import User
  from django.contrib import messages
  
  
  
  
  def home(request):
      return render(request, 'home.html')
  
  
  def register(request):
      global user
      if request.method == 'POST':
          user = User()
          user.fname = request.POST['fname']
          user.lname = request.POST['lname']
          user.email = request.POST['email']
          user.password = request.POST['password']
          user.repassword = request.POST['repassword']
  
      if user.password != user.repassword:
          return redirect(&quot;register&quot;)
      elif user.fname == &quot;&quot; or user.password == &quot;&quot; :
          messages.info(request,f&quot;some fields are empty&quot;)
          return redirect(&quot;register&quot;)
      else:
          user.save()
      return render(request, 'register.html')
  </code></pre>
  <p>models.py</p>
  <pre><code>from django.db import models
  
  
  class User(models.Model):
      id=models.AutoField(primary_key=True)
      fname=models.CharField(max_length=100)
      lname=models.CharField(max_length=100)
      email=models.CharField(max_length=50)
      password=models.CharField(max_length=100)
      repassword=models.CharField(max_length=100)
  </code></pre>
  <p>html page</p>
  <pre><code>{%extends 'base.html'%}
  {%load static%}
  
  {%block content%}
  &lt;link rel=&quot;stylesheet&quot; href=&quot;{%static 'css/style.css'%}&quot;&gt;
  &lt;form method=&quot;post&quot;&gt;
      {%csrf_token%}
      &lt;label for=&quot;fname&quot;&gt;First Name&lt;/label&gt;
      &lt;input type=&quot;text&quot; name=&quot;fname&quot; placeholder=&quot;Enter your First Name&quot;&gt;&lt;br&gt;
      &lt;label for=&quot;lname&quot;&gt;Last Name&lt;/label&gt;
      &lt;input type=&quot;text&quot; name=&quot;lname&quot; placeholder=&quot;Enter your Last Name&quot;&gt;&lt;br&gt;
      &lt;label for=&quot;email&quot;&gt;Email&lt;/label&gt;
      &lt;input type=&quot;email&quot; name=&quot;email&quot; placeholder=&quot;Enter your Email&quot;&gt;&lt;br&gt;
      &lt;label for=&quot;password&quot;&gt;Password&lt;/label&gt;
      &lt;input type=&quot;password&quot; name=&quot;password&quot; placeholder=&quot;Enter a password&quot;&gt;&lt;br&gt;
      &lt;label for=&quot;repassword&quot;&gt;Re Password&lt;/label&gt;
      &lt;input type=&quot;password&quot; name=&quot;repassword&quot; placeholder=&quot;Re enter your password&quot;&gt;&lt;br&gt;
      &lt;button class=&quot;btn&quot;&gt;Submit&lt;/button&gt;
  &lt;/form&gt;
  {%endblock%}
  </code></pre>