2

Disclaimer: I am new to python but have coded in Drupal where I used ajax, jquery, json

I need to create a simple web app front-end (using jquery, AJAX, css) for my python backend. I successfully followed the instructions on this stackoverflow question page, but the WSGI-served html refuses to load my html's stylesheets and jquery.js. In the previously mentioned link, S.Lott wrote, "The demo_app is relatively easy to write; it handles your Ajax requests." I (believe that I) understand the demo_app and much of his "WSGI implementation," but obviously not enough. I'm happy to research the answer but need a nudge in the right direction. Thanks!

Community
  • 1
  • 1
mellow-yellow
  • 1,670
  • 1
  • 18
  • 38
  • Out of curiousity, why are you using wsgi directly? If it's just for edification, that's fine, if not, you might want to read PEP 0333 http://www.python.org/dev/peps/pep-0333/. Specifically this section: "this should not be construed to mean that application developers will use WSGI as a web programming API! It is assumed that application developers will continue to use existing, high-level framework services to develop their applications. WSGI is a tool for framework and server developers, and is not intended to directly support application developers." – Wilduck Feb 24 '12 at 22:51
  • If you're looking to just get a website up and running quickly with python, I would look in to flask: http://flask.pocoo.org/. – Wilduck Feb 24 '12 at 22:52

1 Answers1

1

WSGI is an interface between the webserver (like Apache) and your Python web application. It provides a standard way of running Python code on web servers.

You do not need WSGI to serve static files like JavaScript or CSS (because JS/CSS is not a Python code). Configure your web server to serve static files in a normal way, apart of your WSGI-based Python web application.

With Apache typical solution is to use Alias directive:

Alias /media/ /usr/local/www/documents/media/              # Static files, e.g. http://example.com/media
WSGIScriptAlias / /usr/local/www/wsgi-scripts/myapp.wsgi   # WSGI app mounted at the root of site, e.g. http://example.com
Mariusz Jamro
  • 30,615
  • 24
  • 120
  • 162
  • Thank you. After reading "You'll be reinventing quite a few wheels if you work at such a low level of abstraction. Have you considered using a web framework?" from http://mail.python.org/pipermail/python-list/2011-February/1265524.html, I think I need to install Django, since my project will involve processing LOTS of scripts. Thank you! – mellow-yellow Feb 24 '12 at 23:17
  • There are other frameworks too: http://www.wsgi.org/en/latest/frameworks.html, however Django has really great community and lot of docs. – Mariusz Jamro Feb 24 '12 at 23:20