title: Django extending user with userprofile (error: User has no profile.)
body: <p><a href="https://i.stack.imgur.com/h9Wcd.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/h9Wcd.png" alt="enter image description here"></a>someone can told me, why this code don't working?
  I'm trying to create a registration form for users.</p>
  
  <blockquote>
    <p>I'm getting an error</p>
    
    <p>"RelatedObjectDoesNotExist at /signup/client/2/ User has no profile."</p>
  </blockquote>
  
  <p>views.py</p>
  
  <pre><code>if request.POST:
              user_form = UserCreationForm(request.POST)
              profile_form = ProfileForm(request.POST)
              if user_form.is_valid() and profile_form.is_valid():
                  user = user_form.save()
                  user.profile.city="WW"
                  user.profile.phone="32323"
                  user.profile.save()
  </code></pre>
  
  <p>forms.py</p>
  
  <pre><code>class UserForm(forms.ModelForm):
      class Meta:
          model = User
          fields = ('first_name', 'last_name', 'email')
  
  class ProfileForm(forms.ModelForm):
      class Meta:
          model = Profile
          fields = ( 'city', 'phone')
  </code></pre>
  
  <p>html file</p>
  
  <pre><code>  &lt;h2&gt;Sign up&lt;/h2&gt;
    &lt;form method="post"&gt;
      {% csrf_token %}
      {{ user_form.as_p }}
      {{ profile_form.as_p }}
      &lt;button type="submit"&gt;Sign up&lt;/button&gt;
  </code></pre>
  
  <p>models.py</p>
  
  <pre><code>from __future__ import unicode_literals
  from django.contrib.auth.models import User
  from django.db import models
  from django.db.models.signals import post_save
  from django.dispatch import receiver
  
  class Profile(models.Model):
      user = models.OneToOneField(User, on_delete=models.CASCADE)
      city = models.TextField(max_length = 50)
      phone = models.TextField(max_length = 12)
  </code></pre>