The Wiert Corner – irregular stream of stuff

Jeroen W. Pluimers on .NET, C#, Delphi, databases, and personal interests

  • My badges

  • Twitter Updates

  • My Flickr Stream

  • Pages

  • All categories

  • Enter your email address to subscribe to this blog and receive notifications of new posts by email.

    Join 4,224 other subscribers

Archive for January 23rd, 2014

Generate HTML Tables Clean and Fast

Posted by jpluimers on 2014/01/23

I wish I had found about Generate HTML Tables Clean and Fast years ago.

Every once in a while I want to generate the source code for an HTML table with some content easily.

I’ve found no tool doing this in an easy manner and starts in a split second.

But the web page Generate HTML Tables Clean and Fast does.

Correction: did. It is now off-line, but the Blended Technologies » Blog Archive  blog posts about it are still online: Introducing TableGen – The HTML Table Generator and Tablegen Goes Open Source, as is the WayBack machine archive for it.

So I installed Python on my openSUSE server according to Embedding Python In Apache2 With mod_python (… OpenSUSE) | HowtoForge, (could as well have configured in httpd.conf in stead of python.conf: no difference between installing mod_python via httpd.conf and conf.d in apache) then installed the TableGen source there.

(Note: more python.conf examples)

That would still have Python generate a 404 error (uncool: a python generated 404 error does not leave a log of the cause anywhere), not because the was absent, but because it was written in old style “print” statements, not using the new style def index(req); way (thanks Senthil Kumaran, and AJ. for your answer).

So I did some research (this was my first encounter with Python) at for instance Paul Osman : Introduction to mod_python, then rewrote the print parts of the script into string concatenations, then return the full HTML.

(Note: if there is a print "Content-Type: text/html" (for instance demonstrated in Hello World | Web Python), you can omit it, or set the req.content_type like req.content_type = 'text/html' which usually is determined automatically by Python).

That caused quite a few IndentationError: expected an indented block quote errors: python is indentation sensitive (I hadn’t used a language depending on that for ages), and gives a confusing error when you have a colon (:) followed by an unindented docstringPython: I’m getting an ‘indented block’ error on the last 3 quotes (“””).

Then it still didn’t completely work: the form parameters would not be obtained correctly, so I read further, found 3.1 A Quick Start with the Publisher Handler and started to fix that too. That took way too long, so I found out that “mod_python” is not very much maintained any more and “mod_wsgi” is the way to go.

So I disabled the “python” module in YaST2, removed “/etc/apache2/conf.d/python.conf”, then installed the “apache2-mod_wsgi” software package in YaST2, then added the “wsgi” module to HTTP Server Configuration list of Server Modules (it automatically gets enabled) and saved the configuration.

These steps modified the APACHE_MODULES in /etc/sysconfig/apache2, restarted apache with “rcapache2 restart”. You can verify with “httpd2 -M” which modules are loaded. The list should exclude “python_module (shared)” and includes “wsgi_module (shared)”.

Most of this is described in has anyone gotten mod_wsgi working.

Python is whitespace sensitive, but you can have multiple statements on one line. That’s why Python allows semicolons after each statement.

Read Setting up Python with WSGI on Apache for a directory – Stack Overflow.

Read PyCon Conference Slides – Sydney 2010 – Python WSGI adapter module for Apache.

Read Graham Dumpleton: Why are you using embedded mode of mod_wsgi?.

Read Serving Python scripts with Apache mod_wsgi, part I | Leave No Bit Unturned.

Read Parsing the Request – Get | Web Python.

Watch WSGI Tutorial. It explains a lot, including Accessing POST Data from WSGI.

Error “Attempt to invoke directory as WSGI application” -> you cannot do that, there is no way to map a directory to an “” in that directory.

For importing .py files from the same directory as your main .py file:

    import os
    import sys

    directory = os.path.dirname(__file__)
    sys.path.insert(0, directory)

    from webutils import *

Start using The Web framework for perfectionists with deadlines | Django.

A few really cool things about this page:

  • It is a web page, so easy to reach
  • It starts fast
  • You can increase the column/row count without loosing the entered data
    (as it stores the contents as a URL)
  • It can generate a thead for you
    (but not a tfoot)

Generating something like this was a breeze: Read the rest of this entry »

Posted in *nix, Apache2, Development, HTML, Linux, openSuSE, Power User, Software Development, SuSE Linux, Tumbleweed, Web Development | Leave a Comment »

%d bloggers like this: