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