from django template import RequestContext from django shortcuts impor

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
from django.template import RequestContext
from django.shortcuts import render_to_response
from django.contrib.auth.models import User
from django.contrib.auth.decorators import login_required
@login_required
def user_profile(request):
user = User.objects.get(pk=request.user.id)
profile = user.get_profile()
field_names = [f.name for f in profile._meta.fields]
field_names2 = [f.name for f in user._meta.fields]
values = []
for field_name in field_names:
values.append(getattr(profile,field_name))
for field_name in field_names2:
values.append(getattr(user,field_name))
field_names.extend(field_names2)
user_data = zip(field_names,values)
return render_to_response('profile.html',{'user_data':user_data},context_instance=RequestContext(request))