title: How to get userprofile in django 2.0
body: <p>I read a few post already, but I couldn't find what I was looking for.</p>
  
  <p>I'm trying to figure out how to get the UserProfile of a user. I created a one to one field relationship when I create the User Profile. I thought I could just query the UserProfile as is, but I can't get it to work.</p>
  
  <pre><code>def profile_edit(request):
      user = UserProfile.objects.get(user=request.user)
      return render(request, 'medium/profile_edit.html', {'user_profile_form': form,
  
                                                      'current_user': user})
  </code></pre>
  
  <p>Any thoughts? Here's my models.py and views </p>
  
  <h1>models.py</h1>
  
  <pre><code>class UserProfile(models.Model):
      user = models.OneToOneField(settings.AUTH_USER_MODEL,
                              on_delete=models.CASCADE,)
      bio = models.TextField(blank=True)
      avatar = models.ImageField(upload_to='avatars', blank=True)
  </code></pre>
  
  <h1>views.py</h1>
  
  <pre><code>def register_user(request):
  registered = False
  
  if request.method == 'POST':
      user_form = UserForm(data=request.POST)
      user_profile_form = UserProfileForm(data=request.POST)
  
      if user_form.is_valid() and user_profile_form.is_valid():
          new_user = user_form.save()
          new_user.set_password(new_user.password)
          new_user.save()
  
          new_user_profile = user_profile_form.save(commit=False)
          new_user_profile.user = new_user
  
          if 'avatar' in request.FILES:
              new_user_profile.avatar = request.FILES['avatar']
  
          new_user_profile.save()
          registered = True
      else:
          print(user_form.errors, user_profile_form.errors)
  else:
      user_form = UserForm()
      user_profile_form = UserProfileForm()
  return render(request, 'medium/registration.html', {
      'user_form': user_form,
      'user_profile_form': user_profile_form,
      'registered': registered
  })
  </code></pre>