Если я хочу вставить переменную% s в эту
<p><img src= %s alt="tetris"/></p>
У меня проблема в том, что если я использую "%s"
, он не распознает его как плашдолер.
Но если просто использовать %s
, это не будет ссылаться на мое изображение.
Есть ли способ обойти это?
Я попытался вставить URL, который вставлен туда, как это в базе данных ''/url/''
.
Но это тоже не поможет.
Есть предложения?
@ Томас:
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)