Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

435
Visualizações
Can we render .ejs file using flask?

I am currently learning flask framework after completing my node.js and express. I just want to know can we render .ejs file also in flask as we can do in node js.

over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

As far as I can tell there is no Python library capable of rendering .ejs (Embeddable JavaScript Template) files. This is most likely because of the fact that ejs files permit a lot of JavaScript syntax (if not arbitrary JavaScript). So implementing that within Python would be a pain. However there are a ton of templating languages with Python support (see this page on the Python wiki for a list). That said, you could theoretically just execute ejs as a separate process:

import json
import subprocess

from flask import Flask
app = Flask("app")

data = {
  "title": "Example",
  "user": { "firstName": "World" },
  "messages": [ "foo", "bar", "baz" ]
}

@app.route("/")
def hello_world():
  # Note: this assumes you have globally installed ejs with: npm install -g ejs
  ejsRenderer = subprocess.Popen(
    ["ejs", "example.ejs"], stdin=subprocess.PIPE, stdout=subprocess.PIPE)
  rendered = ejsRenderer.communicate(bytes(json.dumps(data), "utf8"))[0]
  ejsRenderer.stdin.close()
  ejsRenderer.wait()
  return rendered

app.run(host="0.0.0.0", port=8080)
over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda