Exthttp module gives an opportunity to register the script like a module with the help of the app.create_module method.

Simple module example:

# ExampleApp
"""
<parameters>
    <company>DSSL</company>
    <author>AATrubilin</author>
    <title>ExampleApp</title>
    <version>1.0.0</version>
</parameters>
"""

from exthttp import create_app, BaseHandler
from exthttp import http

app = create_app("ExampleApp")
app.create_module()

After the launch of the create_module method you will find your module in the list of modules:

Arguments of the create_module method:

  • name (str, optional): Module name, which you will find in the module list. If empty, the script name will be used.
  • icon_path (str, optional): Absolute path or folder script path or path from Trassir to module icon.
  • allow_multiple (bool, optional): Allow to make a few copies of the script. False by default.
    In this mode, the module name always the same as a script name, no matter what we have in the name parameter.

Let's give our script a name and an icon:

# ExampleApp
"""
<parameters>
    <company>DSSL</company>
    <author>AATrubilin</author>
    <title>ExampleApp</title>
    <version>1.0.0</version>
</parameters>
"""

from exthttp import create_app, BaseHandler
from exthttp import http

app = create_app("ExampleApp")
app.create_module(
    name="My First App",
    icon_path="manual/en/gtk-dialog-important.png",
)

One more left. We need to add a request handler for the main page of our module. Wee can use the code from the standard handler.
Final script code:

# ExampleApp
"""
<parameters>
    <company>DSSL</company>
    <author>AATrubilin</author>
    <title>ExampleApp</title>
    <version>1.0.0</version>
</parameters>
"""

from exthttp import create_app, BaseHandler

app = create_app("ExampleApp")
app.create_module(
    name="My First App",
    icon_path="manual/en/gtk-dialog-important.png",
)


@app.route("index")
class IndexHandler(BaseHandler):
    def get(self, request, *args, **kwargs):
        return http.HttpResponse("Hello world")


  • Нет меток