Мне нужно передать строку, а также вернуть шаблон во время выполнения.
Я попытался передать переменную на страницу html, но тестовый пример не пройден, поскольку он подсчитывает теги в выходных данных. Мое условие проверки - передать шаблон, называемый кавычками. html, а также вернуть строку. (Список показан в коде) (Может или не может быть в кавычке. html>
Мой код:
@app.route("/quotes/")
def display_quotes():
return render_template("quotes.html",ans="<h1>Famous Quotes</h1>"+"""<ul>
<li>Only two things are infinite, the universe and human stupidity, and I am not sure about
the former.</li>
<li>Give me six hours to chop down a tree and I will spend the first four sharpening the
axe.</li>
<li>Tell me and I forget. Teach me and I remember. Involve me and I learn.</li>
<li>Listen to many, speak to a few.</li>
<li>Only when the tide goes out do you discover who has been swimming naked.</li>
</ul>""")
В кавычках. html:
{{ans|safe}}
Сообщение об ошибке:
def test_response_nquotes(self):
response = self.client.get('/quotes/')
print(response.data)
nquotes = sum([ 1 for quote in self.quotes if quote in response.data ])
> assert nquotes == 5
E AssertionError: assert 3 == 5
helloapp/tests.py:84: AssertionError
----------------------------- Captured stdout call -----------------------------
b'<h1>Famous Quotes</h1>\n <ul>\n <li>Only two things are infinite, the universe and human stupidity, and I am not sure about the former.</li>\n <li>Give me six hours to chop down a tree and I will spend the first four sharpening the axe.</li>\n <li>Tell me and I forget. Teach me and I remember. Involve me and I learn.</li>\n <li>Listen to many, speak to a few.</li>\n <li>Only when the tide goes out do you discover who has been swimming naked.</li>\n </ul>'
_______________ TestDisplayQuotesView.test_response_valid_quotes _______________
self = <tests.TestDisplayQuotesView testMethod=test_response_valid_quotes>
def test_response_valid_quotes(self):
response = self.client.get('/quotes/')
> assert all([ quote in response.data for quote in self.quotes ])
E AssertionError: assert False
E + where False = all([False, True, True, True, False])
helloapp/tests.py:88: AssertionError
Есть ли способ вернуть шаблон html и строку в Python Flask?
Или какое-нибудь реальное решение для прохождения теста?