Django 1.9 error - 'User' object has no attribute 'profile'
<p>So I recently added an optional user profile model that is linked to a user via a OneToOneField like so:</p>

<pre><code>class UserProfile(models.Model): # Creating class
    user = models.OneToOneField(User, on_delete=models.CASCADE)
</code></pre>

<p>This worked fine, and my current UserProfile models were intact both before and after I added in this field to link the profile to a user.</p>

<p>The problem comes when I log in on the website as a valid user, after submitting the log in form comes an error:</p>

<blockquote>
  <p>AttributeError at /login/</p>
  
  <p>'User' object has no attribute 'profile'</p>
</blockquote>

<p>I have searched through my files for anything along the lines of '<code>User.profile</code>', and similar queries, however I can't seem to find anything that would allow me to properly log in as a user.</p>

<p>I wasn't sure what other code to post here, and didn't want to spam this question with potentially unnecessary code so tell me if there's anything more specific (views.py, models.py, forms.py, etc) that will be needed to solve this sort of problem, or if you know of any possible solutions.</p>

<p>Thank you</p>

<p>You haven't set any related_name attribute on that one-to-one field, so the reverse accessor will be called <code>userprofile</code> not <code>profile</code>.</p>

python django django-models django-views