Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

434
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda