1
如何在不同位置访问多个变量? %s如何看起来像是在杀手点,以及如何在最后正确插入变量。字符串格式化django
谢谢!
下面是代码:
from django.http import HttpResponse
from django.contrib.auth.models import User
from favorites.models import *
def main_page_favorites(request):
title = Favorite.objects.get(id=1).title.upper()
email = User.objects.get(username='Me').email
image = Hyperlink.objects.get(id=3).url
output = '''
<html>
<head>
<title>
Connecting to the model
</title>
</head>
<body>
<h1>
Connecting to the model
</h1>
We will use this model to connect to the model.
<p>Here is the title of the first favorite: %s</p>
</body>
</html>''' % (title, email, image
)
return HttpResponse(output)
您没有使用模板的任何特定原因? – second 2010-08-04 09:37:51
是的,因为我想再次了解基础知识并遵循教程。你知道答案吗? – MacPython 2010-08-04 09:40:42