[Gllug] question about python/perl

Joel Bernstein joel at fysh.org
Thu Feb 24 15:27:11 UTC 2011


On 24 February 2011 16:11, Martin <mherda at gmail.com> wrote:
> Thanks for the clarification on frameworks. It's still somewhat confusing. I
> guess I'd have to try one to be completely
> clear on that.
> I'm a newbie web designer. The few websites I've done are quite simple. I
> code them in emacs (html+css+jquery).
> I haven't used much php yet. If I do, it's for very simple tasks, eg.
> including the header/footer in all pages, etc.
> So to get a few things straight regarding frameworks:
>
> 1. I'd still code html+css+jquery in an editor by hand or do they have a
> template system like CMSs (joomla, drupal) have. (I am aware that CMS
> templates need to be coded first as well.)

The templating system is a wrapper on top of the HTML/CSS that renders
out valid HTML/CSS.
Imagine, for example, a page that displays a set of values from a
database. Assuming a suitable resultset has already been prepared by a
controller, your template can do something like (super-simple
contrived example).

<table>
<th><td>User</td><td>Last logged in date</td></th>
[% FOREACH user IN users %]
<tr><td>[% user.name %]</td><td>[% user.lastlogin %]</td></tr>
[% END %]
</table>

This is the basis of any dynamic server-side templating system, like
PHP or whatever.

> 2. If eg. it's a python framework (eg. django), do I need to know python or
> is it similar to a CMS that you don't need to know the language it's written
> in to use it)
> Here I'm probably confusing a CMS with a web framework.

Yes, you need to know Python / Perl / whatever since your controller
actions will be written in that language.

> 3. My understanding is that web frameworks are more for web applications,
> less for web design (html+css+jquery). I'm confused as to the nomenclature,
> what is a 'web application' ? Can you give me an example of a web
> application? I guess coding some slides or navigation menu in jquery can't
> be called a web application. It's mostly concerned with the website's
> looks.

Yes, precisely. The web application is the software that runs the
backend for your website - it processes form submissions, handles user
authentication, mediates access to databases and so on.

> 4. I haven't had the need to deal with databases yet or anything more
> complex. Does that mean that a web framework
> would not come handy here? I mean you pointed out some advantages of using
> webframeworks and I'd like to use them, but at this stage wouldn't it be an
> overkill?

It would be overkill to use a web framework for things you can do
entirely on the client side, but how many websites today really have
no dynamic server-side component? For example, every AJAX request you
make from jQuery has to return data from somewhere.

You can think of web frameworks as glorified dispatchers. That is, if
you make a request like GET /users/joel/flowers/rose/petals/, it
handles unpacking that URI path and calling the appropriate controller
actions. Clever dispatchers like that in Catalyst allow different,
orthogonal pieces of code to handle different parts of that URI. For
example, you might have one action that deals with /users/<user name>,
captures that username, looks up the user object and stashes it for
further actions to use. You'd then have another for flowers/<flower
name> which looks up the flower by name, stashes the flower object.
Then the petals action does whatever it does (e.g. grab the number of
petals from the stored rose object and stick it into the stash for a
template to render a nice page). As Simon said earlier, it's about
separating different functions from each other, factoring your code in
such a way as to make it sensible, maintainable, reusable and
reflecting the domain it models.

/joel
--
Gllug mailing list  -  Gllug at gllug.org.uk
http://lists.gllug.org.uk/mailman/listinfo/gllug




More information about the GLLUG mailing list