Интеграция асинхронного кода Python с Django

У меня есть асинхронный код python, который приведен ниже и выполняет функцию регистрации:

async def add_account_endpoint(self, request: web.Request):
        """
        Adds account to the list of accounts with username and password
        : param request: Web request from the URL where the parameters will come in
        :return: WebResponse with the outcome of a request
        """
        data = await request.post()
        new_user_name = data.get('user_name')
        new_account_password = data.get('password')
        if new_user_name:
            if new_account_password:
                if new_user_name not in [account.user_name for account in self.accounts]:
                    # Create and add new account to the accounts in the exchange
                    new_account = Account(new_user_name, new_account_password, self.db_handler)
                    self.accounts.append(new_account)
                    return web.Response(content_type='text', body="Account added successfully")
                else:
                    return web.Response(content_type='text', body="Unable to add account: user_name already exists")
            else:
                return web.Response(content_type='text', body="Unable to add account: please give password")
        else:
            return web.Response(content_type='text', body="Unable to add account: please give user_name")

Это код регистрации, в котором происходит добавление пользователя в БД. Теперь я хочу интегрировать его в Django с помощью шаблонов. Как я могу интегрировать его?

Вернуться на верх