Discuss / Python / 打卡

打卡

Topic source

桂兴牛2号

#1 Created at ... [Delete] [Delete and Lock User]

可以运行,写了好多注释。而且我的浏览器是直接弹出一个下载页面,下载下来一个文件,里面写着Awesome,为什么?

我也是。用IE打开就好了。

Chasen_Zh

#3 Created at ... [Delete] [Delete and Lock User]

我的也是这样为什么呢?

疼就喊Ouch

#4 Created at ... [Delete] [Delete and Lock User]
def index(request):
    return web.Response(body=b'<h1>Awesome</h1>', content_type='text/html')

在构造的时候传入content_type就好了

还没测试成功的伙伴可以参考一下这个:

def index(request):
	return web.Response(body = b"<h1>Hi, there!</h1>", headers = {"content-type": "text/html"})



async def init(loop):
	app = web.Application()
	app.add_routes([web.get("/", index)])
	srv = await loop.create_server(web.AppRunner(app), "127.0.0.1", 9090)
	logging.info("the server started")
	return srv


loop = asyncio.get_event_loop()
loop.run_until_complete(init(loop))
loop.run_forever()

测试了一下,使用这个语句代替make_handler()这个语句,同样行不通:服务器好像可以运行,但是没有正常反馈。访问网页,连不通。

srv = await loop.create_server(web.AppRunner(app), "127.0.0.1", 9090)

加这个好用,3楼的***666***

def index(request):

    return web.Response(body=b'<h1>Awesome</h1>', content_type='text/html'**)

blueeye

#8 Created at ... [Delete] [Delete and Lock User]

谢谢楼上的兄弟!加油!


  • 1

Reply