Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Serving static files with WSGI and Python 3

What is the simplest way to serve static files with WSGI and Python 3.2? There are some WSGI apps for PEP 333 and Python 2 for this purpose - but was is about PEP 3333 and Python 3? I want to use wsgiref for development.

like image 410
deamon Avatar asked Jul 20 '11 06:07

deamon


People also ask

Can uWSGI serve static files?

Fortunately uWSGI has a wide series of options and micro-optimizations for serving static files. Generally your webserver of choice (Nginx, Mongrel2, etc.) will serve static files efficiently and quickly and will simply forward dynamic requests to uWSGI backend nodes.

What is WSGI file in Python?

Django's primary deployment platform is WSGI, the Python standard for web servers and applications. Django's startproject management command sets up a minimal default WSGI configuration for you, which you can tweak as needed for your project, and direct any WSGI-compliant application server to use.

How do I start WSGI application?

Your First WSGI App Call it app.py and run it with any WSGI-compatible server and you'll get a Hello World response with a 200 status. You can use gunicorn for this; just install it via pip ( pip install gunicorn ) and run it with gunicorn app:app .


2 Answers

Typically, you don't want to serve static files using WSGI. WSGI is used so that dynamic content can be generated by using Python. Static files, by definition, are not dynamic content, so you don't need the additional layer of WSGI and any web app you've built on it. Instead, you would be best to set up your web server (apache, nginx, iis, etc.) to serve the static files separately, alongside your WSGI application.

Edit: Interestingly, I JUST found myself in this spot after you clarified your issue. Here's something I found that you might appreciate. It's called "static".

https://github.com/lukearno/static

like image 113
Mark Hildreth Avatar answered Oct 17 '22 08:10

Mark Hildreth


Bottle supports PEP 3333, serving static files and is very small. It might fit the bill for you. I agree with Mark Hildreth's answer, but if you need static serving for development and to work with Python 3, Bottle is a good bet. Note: Bottle uses 2to3.

like image 35
Vinay Sajip Avatar answered Oct 17 '22 08:10

Vinay Sajip