title: pre-populated form if a record exists
body: <p>If the user clicks on 'profile/edit/' link a template is loaded.</p>
  
  <p>But i want the fields in the template to be pre-populated if a record already exists.</p>
  
  <p>I tried this but it doesn't seem to work.</p>
  
  <pre><code>def editprofile(request):
      if request.user.is_authenticated():
          try:
              userprofile = UserProfiles.objects.get(user=request.user)
              form = UserProfileForm(request.POST, instance=userprofile)
          except UserProfiles.DoesNotExist:
              userprofile = None
          if userprofile:
              return render_to_response('profile_edit.html', {'form':form}, context_instance=RequestContext(request))
          else:
              return render_to_response('profile_edit.html', {'form':UserProfileForm()}, context_instance=RequestContext(request))
  </code></pre>