나는 내가 "%s"
를 사용하는 경우, 그것은 습관이있는 placholder로 인식하는 문제가이장고 문자열 형식
<p><img src= %s alt="tetris"/></p>
에 변수 % s을 (를) 삽입합니다. 그러나 단지 %s
을 사용하면 내 이미지에 연결되지 않습니다.
이 방법이 있습니까? 데이터베이스에 삽입 된 URL을 삽입하려고했습니다 (''/url/''
). 그러나 그 트릭도하지 않을 것입니다. 제안 사항이 있으십니까?
@thomas :
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>
<p>Here is your email: %s </p>
<p>Here is the url: %s </p>
<p>Here is the url embedded in an image: <p><img src= %s alt="tetris"/></p>
</body>
</html>''' % (
title, email, image, image
)
return HttpResponse(output)
예제 코드를 제공해 줄 수 있습니까? ' '
'% "foo.jpg"는 효과가 있습니다. –죄송합니다. 데이터베이스에서 해당 변수를 검색한다고 말한 것을 잊었습니다. 그래서 % s이 (가) image로 대체되었습니다. 이미지가 다음과 같이 정의됩니다. image = Hyperlink.objects.get (id = 3) .url – MacPython
여전히 문제가 아닙니다. 스크립트의 정확한 코드를 붙여 넣을 수 있습니까? –