Page syntax

Pages allow you to generate Views & and basic structure for templates.

Page body

Page body can contain variable declarations, python code and annotations.



var_name := python_code
var_name := python_code
var_name := python_code
var_name := python_code
var_name := python_code
{ source python code ..

@annot .. annotation body ..
@annot .. annotation body ..
@annot .. annotation body ..
@annot .. annotation body ..


Variables are values that are forwarded to page templates and all other page parts.

Syntax is following:

[variable_name] := [line of python code] .. expression annotations ..

Line of code is a one-line python expressions (Python expression). You can also use Code imports to use external code in expression.

Each next variable can use the result of previous declarations as a local python variable:

[index: /]
boo:= 123
foo:= 777 - boo

You can access the Django request object:

[index: /]
me:= request.user

There is a special “url” object that gives access to url parameters:

[index: /myurl/<param1>/<param2>/<pk>]
foo:= "Params are: {}, {}.".format(url.param1, url.param2)
cat:= Cat.objects.get(

Variable annotations

Currently only one annotation exist: @or_404 It is very useful for handling DoesNotExist exception:

[index: /cat/<cat_id>]
cat:= Cat.objects.get(pk=url.cat_id) @or_404

Instead of showing exception, it shows proper Http404 error to user.

Python code

If you need to run custom python code, you can do it:

[boo] {
    print("That's my code!")

Or combined with variables:

foo = 123
    print(f"That's my code! Variables are also available here: {foo}")

And you can assign new variables to “data”:

[boo] {
    data['smth'] = '321'


Annotations are super-powers in Zmei generator. They add different abilities to pages, e.g. @crud generates CRUD subpages to current page:

[cat: /cats/]


Read more about extras in the Model annotations section.