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
#1
Hello all,
          Please I am having a problem modifying wsgi example. The original example is as follows:

import cgi

form = b'''
<html>
   <head>
       <title>Hello User!</title>
   </head>
   <body>
       <form method="post">
           <label>Hello</label>
           <input type="text" name="name">
           <input type="submit" value="Go">
       </form>
   </body>
</html>
'''

def app(environ, start_response):
   html = form

   if environ['REQUEST_METHOD'] == 'POST':
       post_env = environ.copy()
       post_env['QUERY_STRING'] = ''
       post = cgi.FieldStorage(
           fp=environ['wsgi.input'],
           environ=post_env,
           keep_blank_values=True
       )
       html = b'Hello, ' + post['name'].value + '!'

   start_response('200 OK', [('Content-Type', 'text/html')])
   return [html]

if __name__ == '__main__':
   try:
       from wsgiref.simple_server import make_server
       httpd = make_server('', 8080, app)
       print('Serving on port 8080...')
       httpd.serve_forever()
   except KeyboardInterrupt:
       print('Goodbye.')
I am trying to replace the outputted html with javascript code from a library for rendering open street maps like this:

form = b'''
<html>
<title>OpenLayers Simplest Example</title>
<div id="demoMap" style="height:250px"></div>
<script src="OpenLayers.js"></script>
<script>
   map = new OpenLayers.Map("demoMap");
   map.addLayer(new OpenLayers.Layer.OSM());
   map.zoomToMaxExtent();

markers = new OpenLayers.Layer.Markers( "Markers" );
   markers.id = "Markers";
   map.addLayer(markers);
var coordinates = [];

   map.events.register("click", map, function(e) {
        //var position = this.events.getMousePosition(e);
var toProjection = new OpenLayers.Projection("EPSG:4326");
        var position = map.getLonLatFromPixel(e.xy);
var position_t = map.getLonLatFromPixel(e.xy).transform(map.getProjectionObject(), toProjection);
coordinates.push(position_t);
alert(position_t);
        var size = new OpenLayers.Size(21,25);
        var offset = new OpenLayers.Pixel(-(size.w/2), -size.h);
        var icon = new OpenLayers.Icon('images/mark.png', size, offset);   
        var markerslayer = map.getLayer('Markers');

        markerslayer.addMarker(new OpenLayers.Marker(position,icon));

  });
  $( '#coord_id' ).val( JSON.stringify(coordinates) );
  
</script>
<form method="POST" action="" class="">
   <input type="hidden" name="coord" id="coord_id" value="" />
   <input type="submit" name="commit" value="Go" class="float" />
</form>
</html>
When I run the simple server I get a blank page. On trouble-shooting using the browser's view page source function, I discovered that the javascript file is not being loaded. I don't know what to do to get it to load (and for the other code between the second set of script tags to work) or if it's even possible to run javascript in such a manner.
Any pointers to the resolution of this problem would be greatly appreciated.
Reply


Messages In This Thread
Python wsgi example: problem with javascript - by imonike - Jun-13-2017, 10:44 AM

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,265 Jan-09-2021, 06:08 PM
Last Post: eraosa
  WSGI Multi processing. simbha 1 2,894 May-05-2020, 10:34 AM
Last Post: pyzyx3qwerty
  question about using javascript on python selenium Kai 1 1,965 Apr-12-2020, 04:28 AM
Last Post: Larz60+
  wsgi server ports chrisdb 3 3,404 Feb-26-2020, 04:24 PM
Last Post: snippsat
  How can get url from JavaScript in Selenium (Python 3)? m0ntecr1st0 3 4,212 Feb-19-2019, 12:35 AM
Last Post: m0ntecr1st0
  Log WSGI directly to stdout ThomasT 4 3,990 Jan-24-2019, 10:17 AM
Last Post: ThomasT
  Python - Scrapy Javascript Pagination (next_page) Baggelhsk95 3 10,159 Oct-08-2018, 01:20 PM
Last Post: stranac
  Trouble deploying Django (project folder, wsgi.py and libapache2-mod-wsgi) Drone4four 8 8,130 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