是否可以拥有烧瓶应用程序和EJS网站
我正在制作烧瓶应用程序,通常我会执行以下代码:
from flask import (
Flask,
render_template,
request
)
app = Flask(__name__)
@app.route('/', methods=['GET', 'POST'])
def index():
if request.method == 'POST':
# print(request.form.get('hallo'))
pass
return render_template('index.html')
if __name__ == '__main__':
app.run(debug=True)
但是我现在需要对EJS做同样的事情,这是可能的,我可以做:
from flask import (
Flask,
render_template,
request
)
app = Flask(__name__)
@app.route('/', methods=['GET', 'POST'])
def index():
if request.method == 'POST':
# print(request.form.get('hallo'))
pass
return render_template('home.ejs')
if __name__ == '__main__':
app.run(debug=True)
因为那对我不起作用。如果我不能使用烧瓶和EJS,请让我知道与EJ一起使用的是什么。
谢谢
i am making a flask app and usually i would do the following code:
from flask import (
Flask,
render_template,
request
)
app = Flask(__name__)
@app.route('/', methods=['GET', 'POST'])
def index():
if request.method == 'POST':
# print(request.form.get('hallo'))
pass
return render_template('index.html')
if __name__ == '__main__':
app.run(debug=True)
but i now need to do the same thing with EJS, is this possible and could i just do:
from flask import (
Flask,
render_template,
request
)
app = Flask(__name__)
@app.route('/', methods=['GET', 'POST'])
def index():
if request.method == 'POST':
# print(request.form.get('hallo'))
pass
return render_template('home.ejs')
if __name__ == '__main__':
app.run(debug=True)
because that doesnt work for me. IF i can't use flask and ejs please do let me know what would work with ejs.
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
render_template
直接从磁盘读取文件。您必须将其运行为
subprocess
并从此过程中获取结果,然后随后将其与render_template_string
(而不是render_template
)或直接与返回
和类似
flask
编辑:
更有用,可以将代码放在分离的功能中,并使用完整的路径到达
ejs < /code>和使用模板文件夹,
如果您使用
render_ejs(...,debug = true)
然后在控制台中它将显示ejs
的错误。render_template
reads file directly from disk.You would have to run it as
subprocess
and get result from this process, and later use it withrender_template_string
(instead ofrender_template
) or directly withreturn
And similar in
Flask
EDIT:
To make it more useful you can put code in separated function and use full path to
ejs
and to folder with templatesIf you use
render_ejs(..., debug=True)
then in console it will display error fromEJS
.