Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

您好 ,看了您的代码,感觉受益匪浅 #3

Open
Blusez opened this issue Sep 22, 2017 · 2 comments
Open

您好 ,看了您的代码,感觉受益匪浅 #3

Blusez opened this issue Sep 22, 2017 · 2 comments

Comments

@Blusez
Copy link

Blusez commented Sep 22, 2017

有个小问题,想请教一下。
您是在每一个请求中返回web_meta配置信息,
image
我想是不是可以在进行页面跳转的时候,把配置信息直接存进去,这样避免每次都要返回web_meta。
tim 20170922120900
但是总报这种错误:
tim 20170922120910
请问如何解决?
或者有没有别的办法能够实现这个想法?谢谢

@qqj1228
Copy link
Owner

qqj1228 commented Sep 23, 2017

handler(request)返回的数据类型并不一定是dict,只有dict类型才能够执行r['configs']=configs
response_factory的作用就是根据handler(request)返回的不同类型进行处理,使之成为符合aiohttp框架要求的response格式
个人认为在框架的中间件里处理web_meta并不是一个好办法,因为只有返回的是博客页面的时候才需要web_meta,其他情况下(例如所有的api接口)都不需要web_mata。
如果一定要在中间件里实现这个功能的话需要针对不同的返回类型做判断,再处理。

@Blusez
Copy link
Author

Blusez commented Sep 23, 2017

仔细看了看response_factory,终于知道怎么做了!谢谢

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants