[IronPython] Python Pages -- web application stack (like django, rails, ...)

Jonathan Slenders jonathan at slenders.be
Thu Jun 12 01:09:01 CEST 2008


Hi all,

I'm working on a web application framework in Python, and just uploaded the
first release.

Now I quote from my own README. What it actually does is:

- Provide an easy way to embed Python code into HTML, similar to PHP, JPS
and
  other server side languages.
- Make reusing HTML very easy. It uses concepts like master pages and
  including of other pages as a control. This is a very rich template
  mechanism.
- when pages act like web controls for other pages, they are simply
available as
  a member variable of the other pages.
- It contains a built-in HTTP/1.1 web server but also supports CGI.
- Uses clean URLs. There are no .page extensions, and suffixes are available
  as a variable. For instance, if there's a page /test.page, then the URL
  /test/abc will render /test.page, but receive the suffix /abc. This is
totally
  not a new concept, but just very easy to use.
- Output filters for post processing of the generated XHTML tree.
- URLs will always be relative to the page where they've been generated.
  This makes it very easy for included pages to use URLs relative to their
  own even if their in a totally different directory. (This mechanism
  requires an output filter.)
- The render engine has built-in debug functionality. The current
  web based debugger isn't yet ready to use, but the back-end
  has already been implemented.

The target audience is at the moment mainly for programmers, because the
front-end (which I considered less important until now) is uncomplete.

The core has been extensively tested and works pretty well, but some minory
features are missing and therefore I consider the whole alpha quality.

I'm constantly trying to get everything work in IronPython because that's
definitely a great bonus. Until now, it doesn't run in IronPython because it
executes part of the pages though eval while the globals/locals for these
parts are each time passed on the next eval call. (bugs has been submitted
on codeplex, see user:jonathanslenders)

It does however work already with Silverlight. A page can dynamically build
a xap file with Python code in. Thanks to Harry Pierson for the tip!
Because I'm really new to Silverlight and don't know much about it's
capabilities, some research needs to be done, to get the best of this
integration. -- But the concept works very well.

To give you all an idea of the layout of such pages:
One page (a master) may look like this.

<%!page output="xhtml" filters="resolve_uris,highlight_code" %>
<%!content placeholder="Main" %>
<html>
    <head>
        <%!placeholder id="head" %>
    </head>
    <body>
        <%!placeholder id="content" %>
    </body>
</html>

and another may implement his placeholders. This one does some math. Note
the modified python syntax. My compiler compiles these pages to regular
python classes.

<%!page master="/Master" external="true" %>
<%!content placeholder="head" %>
<title>Hello world page</title>
<%!content placeholder="content" %>
<p>
    Let's count to 10:
</p>
<ul>
    <% for i in range(0,10): %>
        <li><%= i %></li>
    <% endfor; %>
</ul>
<%
def factorial(i):
    if i == 0:
        return 1;
    else:
        return i * factorial(i - 1);
    endif;
enddef;
%>
<p>
    The factorial of 10 is <%= factorial(10) %>
</p>

And the Silverlight control:

<%!page master="/controls/silverlight-xap" external="true" %>
<%!content name="python" %>
from System.Windows import Application
from System.Windows.Controls import Canvas
xaml = Application.Current.LoadRootVisual(Canvas(), "app.xaml")
xaml.textblock.Text = 'Hello world from IronPython'
<%!content name="xaml" %>
<Canvas x:Class="System.Windows.Controls.Canvas"
    xmlns="http://schemas.microsoft.com/client/2007"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    x:Name="parentCanvas">
<TextBlock x:Name="textblock" FontSize="30">Hello world from XAML
</TextBlock>
</Canvas>


The source code is available here:

http://code.google.com/p/python-pages/



I hope someone thinks this is interesting.


Jonathan
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/ironpython-users/attachments/20080612/8d90c60e/attachment.html>


More information about the Ironpython-users mailing list