我有一个django项目。我还有一个json ojbect,我想传递给模板并显示模板本身中对象的选定信息。
这是对象(用户):
OrderedDict([
('info',
{
'bio':'brother of founder',
'company':'MySplit',
'dob':'1993-03-23',
'first_name':'hani',
'gender':'M',
'last_name':'jandali',
'phone':'+19515343666'
} ),
('location',
{
'city':'Mission Viejo',
'state':'CA',
'street':'27806 Soller',
'zip_code':92692
} ),
('status',
{
'active':'1',
'group':'dev',
'premium':'1'
} )
])
这是我的模板:
<p>
{{ user_profile.location.street }}
</p>
Views.py文件:
def user_home(request):
if 'uid' not in request.session:
# the following is for a user that is not logged in
login = LoginForm()
signup = SignupForm()
parameters = {
'login':login,
'signup':signup,
}
return render(request, 'users/welcome.html', parameters)
else:
user_id = request.session['uid']
user_profile = database.child('users').child(user_id).child('profile').get()
print(user_profile.key())
print(user_profile.val())
parameters = {
'user_profile':user_profile,
}
return render(request, 'users/user_home.html', parameters)