Skip to main content

Tree type apps

More complex apps, consisting of an entity type hierarchy, can be created by choosing the 'tree' app type in the viktor.config.toml file:

app_type = 'tree'

The file can quickly become cluttered with a lot of code if your app grows in size. For tree-type apps we recommend to separate the code in sub-folders. This can be done by replacing the file with a file called within a folder named app and add sub-folders per entity type. Furthermore, it might be desirable to also split the controller and parametrization classes into separate files. For a hypothetical app with entity types BlueType and GreenType this looks as follows:

├── app
│ ├── blue_type
│ │ ├──
│ │ ├──
│ │ └──
│ ├── green_type
│ │ ├──
│ │ ├──
│ │ └──
│ └── <- this is the new entry point of your app, replacing
├── requirements.txt
└── viktor.config.toml

The files in the entity type sub-folders are required to make Python treat directories containing the file as packages and can be left empty.

Importing controllers

If the controller class is in a separate file, it can be imported in the app's file using Python's import command. For example, a controller class named BlueType in a file blue_type/ can be imported in as follows:

from .blue_type.controller import BlueType  # defines entity type 'BlueType'

If the class name itself does not equal the entity type name, you can import as an alias. For example, a class named Controller in a file blue_type/ can be imported in the app's file to act as the controller for the BlueType entity type as follows:

from .blue_type.controller import Controller as BlueType  # defines entity type 'BlueType'