Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/74.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何使用jinja2和flask在html页面上显示消息?_Html_Python 3.x_Flask_Jinja2 - Fatal编程技术网

如何使用jinja2和flask在html页面上显示消息?

如何使用jinja2和flask在html页面上显示消息?,html,python-3.x,flask,jinja2,Html,Python 3.x,Flask,Jinja2,我想在html页面上打印message方法。它位于构造函数内部,但print()函数仅在终端上运行 {% include 'cabecalho.html' %} <body> <img src="/static/img/logo.png" width="25%"> <hr> {% block conteudo %} <p>{% set character1 =

我想在html页面上打印message方法。它位于构造函数内部,但print()函数仅在终端上运行

    {% include 'cabecalho.html' %}
<body>
    <img src="/static/img/logo.png" width="25%">
    <hr>
    {% block conteudo %}
    
    <p>{% set character1 = character(name='Arqueiro das Sombas',vocation='Paladin',level=32) %}</p>
    <p>{{ character1.name }}</p>
    <p>{{ character1.vocation }}</p>
    <p>{{ character1.level }}</p>
    <p>{{ character1.getvocation() }}</p>
    <p>{% set character2 = character(name='Mordoc Cery',vocation='Knight',level=19) %}</p>
    <p>{{ character2.getname() }}</p>
    <p>{{ character2.messagem(name=character2.getname(),vocation=character2.getvocation(),level=character2.getlevel()) }}</p>
    <p>{{ character2.promotion(level=character2.getlevel(),vocation=character2.getvocation()) }}</p>


    {% endblock %}
</body>
{% include 'rodape.html' %}
class Character():

def __init__(self,name='Guerreiro Silencioso',vocation='Knight',level=99):
    self.name= name
    self.vocation= vocation
    self.level= level
    print(self.messagem(self.name,self.vocation,self.level))

def getname(self):
    return self.name

def setname(self,name):
    self.name = name

def getvocation(self):
    return self.vocation

def setvocation(self,vocation):
    self.vocation = vocation

def setlevel(self,level):
    self.level = level

def getlevel(self):
    return self.level

def messagem(self,name,vocation,level):
    return f"Hello {name}\nWelcome to the game!\nYou are a {vocation} level {level}"

def promotion(self,level,vocation):
    if level < 20:
        print ("You don't have enough level.") #return break method here.
    else:
        if self.getvocation() == 'Knight':
            self.setvocation("Elite Knight")
        if self.getvocation() == 'Paladin':
            self.setvocation("Royal Paladin")
        if self.getvocation() == 'Druid':
            self.setvocation("Elder Druid")
        if self.getvocation() == 'Sorcerer':
            self.setvocation("Master Sorcerer")

    return (self.messagem(self.getname(),self.getvocation(),self.getlevel()))