SpecialistOff.NET / Вопросы / Статьи / Фрагменты кода / Резюме / Метки / Помощь / Файлы

Список вопросов Печать

Как сделать минимальный контроллер для Turbogears?


Метки: turbogears python 

Ответы

RemiZOffAlex  Создано: 2026-02-20 08:00:51.549975  Обновлено: 2026-02-20 08:00:51.549992

app/controllers/root.py

class Actor:
    def __call__(self, environ, context):
        status = '200 OK'
        response_body = 'ok'
        content_type = 'text/html'
        headers = [
            ('Content-Type', content_type),
            ('Content-Length', str(len(response_body.encode('utf-8')))),
            ('Access-Control-Allow-Origin', '*')
        ]
        response = context(status, headers)
        return [response_body.encode('utf-8')]

class RootController:
    def __call__(self, *args, **kwargs):
      response = Actor()
        response.status_code = 200
        response.content_type = 'plain/html'
      return response

Возможно будут интересны и другие вопросы