Recommendation for a small web framework like Perl's CGI::Applicationto run as CGI?

Discussion in 'Python' started by excord80, Jan 27, 2009.

  1. excord80

    excord80 Guest

    I need to make a small, relatively low-traffic site that users can
    create accounts on and log into. Scripts must run as cgi (no
    mod_python or FastCGI is available). Can anyone recommend a small and
    simple web framework for Python, maybe similar to Perl's

    Or would it just be better to roll my own?
    excord80, Jan 27, 2009
    1. Advertisements

  2. excord80

    Tim Chase Guest

    I need to make a small, relatively low-traffic site that users can

    What are you looking for in your framework? Python comes with
    its own CGI module[1]. For the most basic of sites, this works

    However, if you want to be able to easily slide into a bigger
    environment, I've been pleased with WebStack[2] for my
    lightweight needs. It makes light work of transitioning from CGI
    to other stacks such as mod_python, Twisted, WSGI, etc.

    Backed with a simple sqlite DB, and some simple HTML/Python
    templating, just using dict-expansion:

    # template.html contains content like
    # <p><b>field1</b> = %(field1)s</p>
    template = file('template.html').read()
    params = {
    "field1": "value1",
    "field2": "value2",
    return template % params

    Just set up the values in the params-dict, and use it to display
    your template.



    Tim Chase, Jan 27, 2009
    1. Advertisements

  3. excord80

    excord80 Guest

    Thanks, Tim. I don't think WebStack is what I'm looking for, but will
    investigate doing things by hand with the cgi module and using
    Python's own built-in simple templating.
    excord80, Jan 27, 2009
  4. excord80

    excord80 Guest

    Well, let's see. I don't need a templating library, since -- as you
    pointed out -- I can just use Python's own. I don't need a db
    interface (can just make my own dbapi calls if needed). Don't need url
    mapping (can just use mod_rewrite rules in my .htaccess to point at my
    cgi scripts). Don't think I need any i80n. And I don't need an admin
    interface. ... It would seem that I don't need a whole lot at the
    excord80, Jan 28, 2009
  5. excord80

    James Mills Guest

    One option is to configure Apache with mod_wsgi and just
    use WSGI. Fairly simple really and much like CGI.

    James Mills, Jan 28, 2009
  6. excord80

    excord80 Guest

    This is a shared hosting arrangement, so I don't have the option of
    adding an apache module. Also, if it's much like CGI, I don't see what
    benefit it would provide over CGI in this situation.
    excord80, Jan 28, 2009
  7. Worth highlighting with mod_wsgi is that you also don't have to have
    everything inside of one WSGI application and can still use CGI like
    approach of lots of WSGI script files. That is, you are relying on
    Apache dispatching of URLs for file based resources and thus no Python
    specific dispatcher needed, nor mod_rewrite rules.

    Because each WSGI script files is given their own persistent sub
    interpreter by default, with this approach you probably though want to
    force them to all run in same sub interpreter to reduce memory usage.
    This can be done using WSGIApplicationGroup directive.

    For further information see:

    Graham Dumpleton, Jan 28, 2009
  8. excord80 a écrit :
    What about:

    (yes, it is a port of CGI::Application, and FWIW it's mentionned on the
    CGI::Application's wiki).

    Bruno Desthuilliers, Jan 28, 2009
  9. Werkzeug[1] should be in your line, I think.

    Jeroen Ruigrok van der Werven, Jan 28, 2009
  10. excord80

    excord80 Guest

    Nice find. Thank you. Interesting project. It seems to be only one
    fairly short file (perhaps that's all it takes), and its most recent
    release was in 2004. No mailing list.
    excord80, Jan 28, 2009
  11. excord80

    excord80 Guest

    Again, the solution must work for plain vanilla CGI. I don't have WSGI
    available. But thank you.
    excord80, Jan 28, 2009
  12. It works for plain CGI. I myself use it for FCGI.
    Jeroen Ruigrok van der Werven, Jan 28, 2009
  13. excord80

    excord80 Guest

    Thanks, Jeroen. After looking at the Werkzeug "deploying" page, it
    seems as though one is able to write a WSGI webapp and have it work
    via CGI using something called wsgiref. Sounds good.

    If that's correct, it would be great if there were a Werkzeug tutorial
    on deploying it for use with CGI.

    Will look into wsgiref and Werkzeug. Thanks!
    excord80, Jan 28, 2009
  14. That would be something close to Karrigell...
    Fred Pacquier, Jan 28, 2009
  15. excord80

    excord80 Guest

    You know, I stumbled across Karrigell while looking around but was
    initially uninterested because of what initially seems like a lack of
    direction. That is, they tell you that you can use it any way you

    * python script
    * K service
    * html inside python
    * python inside html
    * cgi script

    So, I wasn't sure what to make of that. However, perhaps it's a
    strength... will have to look more into K.

    excord80, Jan 28, 2009
  16. There are some real life frontends for CGI, FCGI and WSGI in Zine[1]. Look
    in the servers directory in the repository.

    I'll double check the documentation and expand where necessary.

    Jeroen Ruigrok van der Werven, Jan 29, 2009
  17. excord80 a écrit :
    It is. And given the intended context (CGI...), it's a GoodThing !-)
    Nope. But does it need new release or a mailing list ? As you say, it's
    just a pretty simple module. The point is that you are very likely to
    fork it for your own needs anyway - so see it as a good starting point
    for a simple lightweight CGI/mod_python (and why not WSGI) framework.
    Bruno Desthuilliers, Jan 29, 2009

    pretty simple. lots of deployment options.

    ends up building into your own framework as your application grows.
    J Kenneth King, Jan 29, 2009
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.