Python Forum
Python wsgi example: problem with javascript
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Python wsgi example: problem with javascript
#10
This one,just the first example i did find.

Here a tips as OpenLayers do most changes in JavaScript,so you need a way to send data to JavaScript.
Jinja2 is a part of Flask also written bye Armin.
With Jinja you can send data(example a Python dictionary) from server to JavaScript.
Example.
app.py:
from flask import Flask, render_template,jsonify,request

app = Flask(__name__)
@app.route('/')
def hello():
   data = {'map': '50', 'site': 'openlayer'}
   return render_template("index.html", data=data)

if __name__ == '__main__':
   app.run(debug=True)
index.html:
<!doctype html>
<html>
 <head>
   <script>
     var some_javascript_var = '{{ data["map"] }}';
   </script>
   <body>
     <p>Hello World</p>
     <button type="button" onclick="alert('Map: {{ data['site'] }} ' + some_javascript_var)"> Click Me!</button>
   </body>
</html>
Reply


Messages In This Thread
RE: Python wsgi example: problem with javascript - by snippsat - Jun-15-2017, 05:26 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Using Python request without selenium on html form with javascript onclick submit but eraosa 0 3,338 Jan-09-2021, 06:08 PM
Last Post: eraosa
  WSGI Multi processing. simbha 1 2,945 May-05-2020, 10:34 AM
Last Post: pyzyx3qwerty
  question about using javascript on python selenium Kai 1 2,008 Apr-12-2020, 04:28 AM
Last Post: Larz60+
  wsgi server ports chrisdb 3 3,490 Feb-26-2020, 04:24 PM
Last Post: snippsat
  How can get url from JavaScript in Selenium (Python 3)? m0ntecr1st0 3 4,329 Feb-19-2019, 12:35 AM
Last Post: m0ntecr1st0
  Log WSGI directly to stdout ThomasT 4 4,081 Jan-24-2019, 10:17 AM
Last Post: ThomasT
  Python - Scrapy Javascript Pagination (next_page) Baggelhsk95 3 10,255 Oct-08-2018, 01:20 PM
Last Post: stranac
  Trouble deploying Django (project folder, wsgi.py and libapache2-mod-wsgi) Drone4four 8 8,251 Mar-17-2018, 09:40 PM
Last Post: Drone4four

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020