gpt4 book ai didi

django - 字符串格式化django

转载 作者:行者123 更新时间:2023-12-05 01:22:07 26 4
gpt4 key购买 nike

如何访问不同位置的多个变量?%s 在插入点必须是什么样子以及最后如何正确插入变量。

谢谢!

代码如下:

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)

最佳答案

不知道你在问什么。您只想在字符串中插入多个值吗?

"value 1 is %s, value 2 is %s." % (value1, value2)

关于django - 字符串格式化django,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3404245/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com