title: How can I allow users to edit their profiles in Django?
body: <p>I have a model in models.py like this:</p>
  <pre><code>class UserProfile(models.Model):
      user = models.OneToOneField(User, on_delete=models.DO_NOTHING)
      phone_number = models.CharField(max_length=50, default='')
      Birthday = models.CharField(max_length=50, default='')
      city = models.CharField(max_length=50, default='')
      school = models.CharField(max_length=100, default='')
      course = models.CharField(max_length=50, default='')
  </code></pre>
  <p>I want to allow my users to make edits, so I made a function like this in my views.py:</p>
  <pre><code>    if request.method == 'POST':
          profil = UserProfile.objects.get(user=request.user)
          profil.phone_number = models.CharField(max_length=50, default='')
          profil.Birthday = models.CharField(max_length=50, default='')
          profil.city = models.CharField(max_length=50, default='')
          profil.school = models.CharField(max_length=100, default='')
          profil.course = models.CharField(max_length=50, default='')
          
          profil.save()
          
          return redirect('profile')  
   
      return render(request, 'edit_profile.html')
  </code></pre>
  <p>My template is:</p>
  <pre><code>&lt;form action=&quot;.&quot; method=&quot;post&quot;&gt;
          {% csrf_token %}    
          Phone Number:
          &lt;input type=&quot;text&quot; name=&quot;phone_number&quot; value=&quot;{{  profil.phone_number }}&quot; /&gt;&lt;br /&gt;
          Birthday:
          &lt;input type=&quot;text&quot; name=&quot;Birthday&quot; value=&quot;{{  profil.Birthday }}&quot; /&gt;&lt;br /&gt;
      
          city:
          &lt;input type=&quot;text&quot; name=&quot;city&quot; value=&quot;{{  profil.city }}&quot; /&gt;&lt;br /&gt;
          school:
          &lt;input type=&quot;text&quot; name=&quot;school&quot; value=&quot;{{  profil.school }}&quot; /&gt;&lt;br /&gt;
      
          course:
          &lt;input type=&quot;text&quot; name=&quot;course&quot; value=&quot;{{  profil.course }}&quot; /&gt;&lt;br /&gt;
         
          &lt;input type=&quot;submit&quot; value=&quot;Save Changes&quot; name=&quot;save&quot; /&gt;
          &lt;input type=&quot;reset&quot; value=&quot;Cancel&quot; name=&quot;cancel&quot; /&gt;
          &lt;br/&gt;
      &lt;/form&gt;
  </code></pre>
  <p>I do not know why, but after filling the form I get an error saying page not found. And if I check the existing user profile nothing got updated. Help please.</p>