Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

304
Views
El valor pasado del matraz a JS funciona en html, no en estático

Necesito llamar a una función de javascript say_hello que existe en una carpeta static y pasar Hello como un mensaje para que se muestre como una alerta. Esto es lo que hago:

app.py

 from flask import Flask, render_template app = Flask(__name__) @app.route('/') def hello(): return render_template('index.html', data={'message': 'Hello'}) if __name__ == '__main__': app.run()

Esto funciona:

index.html

 <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Title</title> </head> <body> <script> const message = {{data.message|tojson|safe}} alert(message); </script> </body> </html>

Esto no funciona:

 <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Title</title> </head> <body> <script src="/js/hello.js"> const message = {{data.message|tojson|safe}} say_hello(message); </script> </body> </html>

hello.js

 function say_hello(message){ alert(message) }

La consola JS no muestra ningún problema y el mensaje no se muestra, solo una página en blanco.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Cuando una etiqueta <script> tiene un src , su contenido se ignora. Uno o el otro.

 <script src="/js/hello.js"> </script> <script> const message = {{data.message|tojson|safe}} say_hello(message); </script>
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!