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!

2
  • 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 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." Commented Feb 24, 2012 at 22:51
  • If you're looking to just get a website up and running quickly with python, I would look in to flask: flask.pocoo.org. Commented Feb 24, 2012 at 22:52

1 Answer 1

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
Sign up to request clarification or add additional context in comments.

2 Comments

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 mail.python.org/pipermail/python-list/2011-February/…, I think I need to install Django, since my project will involve processing LOTS of scripts. Thank you!
There are other frameworks too: wsgi.org/en/latest/frameworks.html, however Django has really great community and lot of docs.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.