title: Django UserProfile matching query does not exist
body: <p>I'm making an forum using this tutorial <a href="http://lightbird.net/dbe/forum2.html" rel="nofollow noreferrer">http://lightbird.net/dbe/forum2.html</a> and I encountered an error .</p>
  
  <p>When I click edit profile , it suppose to point to this page instead I get an error(below)</p>
  
  <p><img src="https://i.stack.imgur.com/DBOWO.jpg" alt="enter image description here"></p>
  
  <pre><code> DoesNotExist at /forum/profile/1/
  
   UserProfile matching query does not exist.
  
   Request Method:    GET
   Request URL:   http://127.0.0.1:8000/forum/profile/1/
   Django Version:    1.4.3
   Exception Type:    DoesNotExist
   Exception Value:   
  
   UserProfile matching query does not exist.
  
   Traceback Switch to copy-and-paste view
  
   C:\djcode\mysite\forum\views.py in profile
  
           profile = UserProfile.objects.get(user=pk)
  </code></pre>
  
  <p>I think this error mean , django can't receive my admin login .</p>
  
  <p>This is part of my fbase.html </p>
  
  <pre><code>  &lt;a href="{% url ben:profile user.pk %}"&gt;Edit profile&lt;/a&gt;
  </code></pre>
  
  <p>which point to my URLconf.</p>
  
  <pre><code>  from django.conf.urls import patterns,include,url
    from django.contrib import admin
    from django.conf import settings
  
    urlpatterns = patterns('forum.views',
                     url(r'^$','main',name='main'),
                     url(r"^forum/(\d+)/$", "forum",name ="forum"),
                     url(r"^thread/(\d+)/$","thread",name = "thread"),
                     url(r"^post/(new_thread|reply)/(\d+)/$", "post",name = "post"),
                     url(r"^reply/(\d+)/$", "reply" , name ="reply"),
                     url(r"^new_thread/(\d+)/$", "new_thread" , name  ="new_thread"),
                     url(r"^profile/(\d+)/$", "profile",name= "profile"),
    )
  </code></pre>
  
  <p>and into my view function</p>
  
  <pre><code>  def profile(request, pk):
        """Edit user profile."""
        profile = UserProfile.objects.get(user=pk)
        img = None
  
        if request.method == "POST":
            pf = ProfileForm(request.POST, request.FILES, instance=profile)
            if pf.is_valid():
                pf.save()
                # resize and save image under same filename
                imfn = pjoin(MEDIA_ROOT, profile.avatar.name)
                im = PImage.open(imfn)
                im.thumbnail((160,160), PImage.ANTIALIAS)
                im.save(imfn, "JPEG")
        else:
            pf = ProfileForm(instance=profile)
  
        if profile.avatar:
            img = "/media/" + profile.avatar.name
        return render_to_response("forum/profile.html", add_csrf(request, pf=pf, img=img))
  </code></pre>
  
  <p>This is my models.py</p>
  
  <pre><code>  from django.db import models
    from django.contrib.auth.models import User
    from django.contrib import admin
    from string import join
    from mysite.settings import MEDIA_ROOT
  
    class Forum(models.Model):
        title = models.CharField(max_length=60)
        def __unicode__(self):
            return self.title
        def num_posts(self):
            return sum([t.num_posts() for t in self.thread_set.all()])
  
        def last_post(self):
            if self.thread_set.count():
                last = None
                for t in self.thread_set.all():
                    l = t.last_post()
                    if l:
                        if not last: last = l
                        elif l.created &gt; last.created: last = l
                return last
    class Thread(models.Model):
        title = models.CharField(max_length=60)
        created = models.DateTimeField(auto_now_add=True)
        creator = models.ForeignKey(User, blank=True, null=True)
        forum = models.ForeignKey(Forum)
  
        def __unicode__(self):
            return unicode(self.creator) + " - " + self.title
        def num_posts(self):
            return self.post_set.count()
  
        def num_replies(self):
            return self.post_set.count() - 1
  
        def last_post(self):
            if self.post_set.count():
                return self.post_set.order_by("created")[0]
    class Post(models.Model):
        title = models.CharField(max_length=60)
        created = models.DateTimeField(auto_now_add=True)
        creator = models.ForeignKey(User, blank=True, null=True)
        thread = models.ForeignKey(Thread)
        body = models.TextField(max_length=10000)
  
        def __unicode__(self):
            return u"%s - %s - %s" % (self.creator, self.thread, self.title)
  
        def short(self):
            return u"%s - %s\n%s" % (self.creator, self.title, self.created.strftime("%b %d, %I:%M %p"))
  short.allow_tags = True
  
    ### Admin
  
    class ForumAdmin(admin.ModelAdmin):
        pass
  
    class ThreadAdmin(admin.ModelAdmin):
        list_display = ["title", "forum", "creator", "created"]
        list_filter = ["forum", "creator"]
  
    class PostAdmin(admin.ModelAdmin):
        search_fields = ["title", "creator"]
        list_display = ["title", "thread", "creator", "created"]
    class UserProfile(models.Model):
        avatar = models.ImageField("Profile Pic", upload_to="images/", blank=True, null=True)
        posts = models.IntegerField(default=0)
        user = models.ForeignKey(User, unique=True)
  
        def __unicode__(self):
            return unicode(self.user)
  </code></pre>