Can anyone help me run python scripts with http.server?

Chris Warrick kwpolska at gmail.com
Sun Sep 6 14:16:37 CEST 2015


On 6 September 2015 at 13:50,  <tropical.dude.net at gmail.com> wrote:
> Hello everyone,
>
> I want to use python for web development but I
> could not configure my Apache server to run python
> with the guides I found on the internet.
>
> Can anyone help me configure http.server
> to run python scripts?
>
> I ran the command python -m http.server --cgi to start the http server,
> and if I put index.html, I will see the page but if I use
> index.py, it doesn't show the page, I can only see the
> directory listing of the files and when I click on
> index.py, it doesn't run the code, I can see it just
> like in the editor.
>
> Can anyone help me out?
>
> Thanks in advance.
> --
> https://mail.python.org/mailman/listinfo/python-list

Don’t use http.server. Don’t use CGI. This is not how things work in Python.

In Python, you should use a web framework to write your code. Web
frameworks include Flask, Django, Pyramid… Find one that’s popular and
that you like, and learn that. You won’t have any `.py` URLs, instead
you will have modern pretty URLs with no extensions. And a lot of
things will be abstracted — no manual header creation, help with safe
forms and databases.

And then you will need to figure out how to run it. I personally use
nginx and uwsgi for this, you may need to look for something else.

Examples for Django:

https://docs.djangoproject.com/en/1.8/#first-steps
https://docs.djangoproject.com/en/1.8/howto/deployment/wsgi/

-- 
Chris Warrick <https://chriswarrick.com/>
PGP: 5EAAEA16


More information about the Python-list mailing list