如何为discord.py bot在python中使用sanic运行锁html文件?

问题描述

所以我将discord.py机器人连接到了一个新网站(它是空的) 我有一个带有表单的本地html文件 我想让html在Py文件中运行 因此用户可以填写表格并点击提交 但我不知道该怎么做 因为我仍然不熟悉这些网络内容

我如何运行该html文件

此app.py文件位于名为cogs的文件夹中

from flask import Flask,render_template,redirect,url_for,request
import pyrebase
from aiohttp import web,ClientSession
import asyncio
import discord
from discord.ext import commands
from sanic import response,Sanic
from sanic.blueprints import Blueprint
import os
import json

flask_app = Flask(__name__)
sanic_app = Sanic(__name__)

    async def verified(self):
        async def send(request):
            embed_title = "Test"
            embed = discord.Embed(title=embed_title,color=discord.Color.green())
            channel = self.client.get_channel(695780531912179772)
            await channel.send(embed=embed)
            return await response.file("cogs/verified.html")

        async def posts(request):
            return await response.file("cogs/posts.html")

        app = web.Application(loop=self.client.loop)
        app.router.add_post('/verified',send)
        app.router.add_get('/posts',posts)
        runner = web.AppRunner(app)
        await runner.setup()
        self.site = web.Tcpsite(runner,'0.0.0.0',5000)
        await self.client.wait_until_ready()
        await self.site.start()

def setup(client):
    ts = TestServer(client)
    client.add_cog(ts)
    client.loop.create_task(ts.verified())

此html文件位于同一文件夹cogs中


{% extends "base.html" %}
<!--HEAD-->
{% block head %}
<title>TEST posts 1</title>

{% endblock %}
<!--HEAD end-->

<!--STYLE-->
{% block style %} {% endblock %}
<!--STYLE end-->

<!--BODY-->
{% block body %}
<div class="center">
    <h1>This is posts</h1>

     <div class="side">
         <a href="index">Click to go to index</a><br>
         <a href="home">click to go to home</a><br>
         <a href="new">Click to go to new</a><br>
           <a href="/result">click to go to result</a><br>
    <a href="/student">click to go to student</a><br>

          <a href="verified">click to go to verified</a>
     </div>
</div>
{% for s in stuff1%}
<h1>{{s.title}}</h1>
<p>{{s.content}}</p>
{% endfor %}
<form action="/verified" method="POST">
    <div class="side">
        <h3>Sign up</h3>

    Author:<input type="text" name="author">
        Email:<input type="email" name="email">
        Phone no.:<input type="number" name="phone no">
    Submit:<input type="submit" value="submit">
    </div>
</form>
{% endblock %}
<!--BODY end-->

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)