title: NameError at /register/ name 'user' is not defined
body: <p>I am currently developing a blogging webapp and I tried to extend my Django User Framework With a One To One Field, everything is working fine, but when I'm trying to register a new user, it's throwing a NameError. It is also worth noting that the user is being created and stored(I checked it from the admin page). It is saying that this statement <code>profile.user = user</code> in my views.py is creating the problem. Can anyone please help me with this?</p>
  
  <p>my views.py</p>
  
  <pre><code>from django.shortcuts import render, redirect
  from django.contrib import messages
  from django.contrib.auth.decorators import login_required
  from .forms import UserRegisterForm, ProfileForm
  
  
  def register(request):
      if request.method == 'POST':
          form = UserRegisterForm(request.POST)
          profile_form = ProfileForm(request.POST)
          if form.is_valid() and profile_form.is_valid():
              form.save()
              profile = profile_form.save(commit=False)
              profile.user = user  
              profile.save()
  
              username = form.cleaned_data.get('username')
              messages.success(request, f'Your account has been created! You are now able to log in')
              return redirect('login')
      else:
          form = UserRegisterForm()
          profile_form = ProfileForm
      return render(request, 'users/register.html', {'form': form, 'profile_form': profile_form})
  
  @login_required
  def profile(request):
      return render(request, 'users/profile.html')
  </code></pre>
  
  <p>my models.py</p>
  
  <pre><code>from django.db import models
  from django.contrib.auth.models import User
  
  
  class Profile(models.Model):
      user = models.OneToOneField(User, on_delete=models.CASCADE)
      image = models.ImageField(default='default.jpg', upload_to='profile_pics')
      CHOICES = (
          ('AB+', 'AB+'),
          ('AB-', 'AB-'),
          ('A+', 'A+'),
          ('A-', 'A-'),
          ('B+', 'B+'),
          ('B-', 'B-'),
          ('O+', 'O+'),
          ('O-', 'O-'),
          )
      bloodgroup = models.CharField(max_length=100, choices= CHOICES)
      bio = models.TextField(max_length=300)
  
      def __str__(self):
          return f'{self.user.username} Profile'
  </code></pre>
  
  <p>my forms.py</p>
  
  <pre><code>from django import forms
  from django.contrib.auth.models import User
  from django.contrib.auth.forms import UserCreationForm
  from .models import Profile
  
  
  class UserRegisterForm(UserCreationForm):
      email = forms.EmailField()
  
  
  
      class Meta:
          model = User
          fields = ['username', 'email', 'password1', 'password2']
  
      def save(self, commit=True):
          user = super().save(commit=False)
  
          if commit:
              user.save()
          return user
  
  
  class ProfileForm(forms.ModelForm):
      class Meta:
          model = Profile
          fields = ('image', 'bloodgroup', 'bio')
  
  </code></pre>