[Tutor] How to Create Webpage with Python

Walter Prins wprins at gmail.com
Thu Jul 10 10:39:37 CEST 2014


Hi,

On 10 July 2014 02:30, John Cast <jdcast at stanford.edu> wrote:
> Web - Currently it looks like maybe static HTML page(s) generated every time
> my script is run is the right way to go?

It would be one way to proceed, yes, perhaps the most appropriate way
for you for now.

>           It sounds like I need a server on my desktop?

Note that Python includes in the Python standard library a simple HTTP
web server (module SimpleHTTPServer, in Python 3x http.server) which
can be used by itself and is often used (sometimes with
embellishments) by many/most of the Python web frameworks to run web
servers for development/small scale use.

Concretely: you run a command that start a simple Python based HTTP
server that then serves up the generated or development site from your
local machine for review/development purposes.   In the most basic
case you open a command prompt, change directory to your HTML site
contents, then run the command: python -m SimpleHTTPServer

Proper production deployment will depend on the nature of the site.

For a static site (meaning it is in essence just HTML pages), you
would push the site to some suitable webserver you've installed
somewhere (Apache, Nginx, IIS etc.)

For a dynamic site using a web framework you'd need a web server
configured to run your Python based site, meaning you'd need for
example Apache + mod_wsgi with Python and your chosen web framework
installed, in addition to any Database requirements/dependencies (for
example MySQL or PostgreSQL).

>           I need to create a site and host/serve this somehow using my
> server?

Assuming you're going be generating static HTML pages, yes.

>           I don't need a webframework to do this?

No, but you need something to help you generate the HTML pages.
Unless you just want to generate them yourself from absolute scratch,
which of course you can also do.

>           Need some mechanism to get these HTML page(s) to my site?

For a static site, deploying it means copying the site contents (HTML
files and attendant resources) to the correct folder by whatever means
is most convenient, from which the production web server will the
serve it to the intended audience.  An FTP client would be one way,
assuming the web server also has FTP access.  Another would be to make
the web server's root folder into a version control repository (e.g.
git, mercurial or such.) Serving directly from a version control
repository (e.g. say git) would mean you can in essence simply "push"
changes to the live website once you'e happy with your changes.
Regardless of how you deploy it, using version control is recommended
as it will allow you to properly manage your site over time, for
example reverting to a previous version in case of problems.

Walter


More information about the Tutor mailing list