为了正常的体验网站,请在浏览器设置里面开启Javascript功能!

一层一层说网站

2012-10-26 1页 ppt 1MB 37阅读

用户头像

is_008838

暂无简介

举报
一层一层说网站null一层一层说网站一层一层说网站PYTHON WSGI简介 及 常用中间件张沈鹏 42qu.com作者著名的洋葱著名的洋葱请求(Request)的构成请求(Request)的构成1. 网址: 用户输入 2. COOKIE: 网站设置 3. 其他HTTP头: 浏览器GET /@zsp HTTP/1.1 Host: kanrss.com User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; zh-CN; rv:1.9.2.8) Gecko/20100722 Firefox...
一层一层说网站
null一层一层说网站一层一层说网站PYTHON WSGI简介 及 常用中间件张沈鹏 42qu.com作者著名的洋葱著名的洋葱请求(Request)的构成请求(Request)的构成1. 网址: 用户输入 2. COOKIE: 网站设置 3. 其他HTTP头: 浏览器GET /@zsp HTTP/1.1 Host: kanrss.com User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; zh-CN; rv:1.9.2.8) Gecko/20100722 Firefox/3.6.8 Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8 Accept-Language: zh-cn,zh;q=0.5 Accept-Encoding: gzip,deflate Accept-Charset: GB2312,utf-8;q=0.7,*;q=0.7 Keep-Alive: 115 Connection: keep-alive Cookie: B=kwyP64YM; __utma=5797929.751142743.1280312171.1280312171.1280312171.1; __utmb=5797929.5.10.1280312171; __utmz=5797929.1280312171.1.1.utmcsr=(direct)|utmccn=(direct)|utmcmd=(none); Hm_lvt_fc05ad55c7dcadfd714baf512f9146b3=1280312172072; Hm_lpvt_fc05ad55c7dcadfd714baf512f9146b3=1280312287556; __utmc=5797929 Cache-Control: max-age=0响应Response 构成 响应Response 构成 HTTP/1.1 200 OK Server: nginx/0.7.65 Date: Wed, 28 Jul 2010 10:24:29 GMT Content-Type: text/html; charset=UTF-8 Connection: keep-alive Content-Encoding: gzip Content-Length: 6241 张沈鹏(KanRSS.com/码农 行业:互联网)
追随
与客户端支持的HTTP请求头一致的变量.(也就是以"HTTP_"开头命名的变量.)这些变量是否出现都要与HTTP请求头中的变量保持一致. ............... WSGI ServerWSGI Serverimport tornado.wsgi import tornado.httpserver import tornado.ioloop def WSGIServer(port, application): container = tornado.wsgi.WSGIContainer(application) http_server = tornado.httpserver.HTTPServer(container) http_server.listen(port) tornado.ioloop.IOLoop.instance().start()洋葱核洋葱核def app(environ, start_response): status = '200 OK' response_headers = [ ('Content-type','text/plain'), ] start_response(status, response_headers) return ['Hello']1. environ 2. start_response 3. return ['xxxx']Request ParserRequest Parseryaro - Yet Another Request Object http://lukearno.com/projects/yaro/ 1. 简化environ的访问 environ['QUERY_STRING'] hl=zh-CN&source=hp&q=python&aq=f&aqi=&aql=&oq=&gs_rfai= -> req.query = { "hl":"zh-CN", "source":"hp", ....Request ParserRequest Parser2. 封装 start_response status = '200 OK' response_headers = [ ('Content-type','text/plain'), ] start_response(status, response_headers) return ['Hello'] -> from yaro import Yaro @Yaro def hello_world(req): return "Hello World!" 当然, 也被封装一些状态码 yaro.Request.redirect("/xxx/xxx/xxx") 301 status URL RouteURL RouteURL -> Python Function http://kanrss.com/at/cloudwu/t/1270561 -> mysite/ctrl/at/__init__.py @route_render_func def t(id=None): owner = request.owner ... URL RouteURL Route常用方式 正则匹配 application = tornado.web.Application([ (r"/", MainHandler), (r"/story/([0-9]+)", StoryHandler), ]) class StoryHandler(tornado.web.RequestHandler): def get(self, story_id): self.write("You requested the story " + story_id)Url Route -- 文件路径映射Url Route -- 文件路径映射http://mayoufour.googlecode.com/svn/trunk/mypylib/mypy/urlroute.py 创意衍生自 Quixote 查找映射的函数 = { 路径1 :{ 路径2:{ 模块名 : 函数名称 } } } "/at/cloudwu/t/1270561".split("") -> 'at', 'cloudwu', //被当作 at._access(id)函数的参数吃掉 't', '1270561', //被当作 at.t(id)函数的参数吃掉ModelModel 的 映射 CREATE TABLE `user` ( `id` int(10) unsigned NOT NULL AUTO_INCREMENT, `name` varbinary(24) NOT NULL, `url` varbinary(60) DEFAULT NULL, `ver` tinyint(3) unsigned NOT NULL DEFAULT '0', `state` tinyint(3) unsigned NOT NULL DEFAULT '40', PRIMARY KEY (`id`), UNIQUE KEY `url` (`url`), KEY `state` (`state`), KEY `name` (`name`) ) -> user.name , user.state ModelModel表的行为 ban_user -> 设置user.state + 删除user_session使其退出登录 表 与的 表 互动 table user <=> table user follow -> def follower_by_user_id(user_id): ....ControlControl1. 提交表单的数据效验 2. 从Model获取页面需要的数据 3. 权限不对的时候 给出错误提示 if not user.can_admin(group): G.error = "你没有权限管理该小组" -- 传递变量 --> 模板模板 %for i in items: ${i['title']} ${i['link']} ${i['author']} ${format_rfc822_date(i['pubdate'])} ${i['link']} %endfor被遗忘缓存被遗忘缓存Model -> memcache -> Control 1.缓存id列表 mc_book_section_id_ordered_can_view = McCacheA("BookSectionIdOrderedCanView:%s") @mc_book_section_id_ordered_can_view("{id}") def book_section_id_ordered_can_view(id): book_list = book_section_ordered(id) return [ i.id for i in book_list if i.can_view ] 2.缓存对象 user_list = User.mc_get_list(user_id_list) 需要在有改动的时候手工清理被遗忘缓存被遗忘缓存Template -> memcache -> WSGI Server 页面局部的memcache缓存 <%def name="mycomp" cached="True" cache_timeout="300" cache_type="memcached"> other text 节省取数据 + 模板的开销 一般自动超时失效被遗忘缓存被遗忘缓存WSGI Server -> Nginx Proxy Cache -> ... server_name rss_group.kanrss.com; location ~ ^/(\d+)$ { proxy_pass http://kanrss/vgroup/$1/rss_feed; proxy_cache KFS; proxy_cache_valid 200 304 301 302 30m; proxy_cache_valid any 1m; proxy_cache_key "$host$request_uri"; proxy_set_header Host $host; proxy_set_header X-Forwarded-For $remote_addr; } 比如 RSS (firefox会检查收藏夹中的rss更新 -> 压力不小) 比如 一些不经常变的Ajax响应(比如搜索的自动完成?)还没有说的...还没有说的...辅助开发 WEB前端优化 异步运行 长连接 OpenID .... ... .... 更多更多...更多更多...Profile?更多更多...更多更多...Debug?更多更多...更多更多...Auto Restart ?https://mayoufour.googlecode.com/svn/trunk/mypylib/mypy/reloader.py https://mayoufour.googlecode.com/svn/trunk/mypylib/mypy/reload_server.py 4242qu.com区找到给你的人null import sys sys.exit()
/
本文档为【一层一层说网站】,请使用软件OFFICE或WPS软件打开。作品中的文字与图均可以修改和编辑, 图片更改请在作品中右键图片并更换,文字修改请直接点击文字进行修改,也可以新增和删除文档中的内容。
[版权声明] 本站所有资料为用户分享产生,若发现您的权利被侵害,请联系客服邮件isharekefu@iask.cn,我们尽快处理。 本作品所展示的图片、画像、字体、音乐的版权可能需版权方额外授权,请谨慎使用。 网站提供的党政主题相关内容(国旗、国徽、党徽..)目的在于配合国家政策宣传,仅限个人学习分享使用,禁止用于任何广告和商用目的。
热门搜索

历史搜索

    清空历史搜索