设为首页 收藏本站
查看: 558|回复: 0

[经验分享] Python Web 开发框架 Pylons

[复制链接]

尚未签到

发表于 2017-4-28 12:04:28 | 显示全部楼层 |阅读模式
  


3. Pylons




3.1. Getting Started with Pylons





3.1.1. Installing




[neo@development ~]$ curl http://pylonshq.com/download/1.0/go-pylons.py | python - mydevenv
[neo@development ~]$ source mydevenv/bin/activate
(mydevenv)[neo@development ~]$
(mydevenv)[neo@development ~]$ paster create -t pylons helloworld

  Running the application

(mydevenv)[neo@development ~]$ cd helloworld
(mydevenv)[neo@development helloworld]$ paster serve --reload development.ini
Starting subprocess with file monitor
Starting server in PID 26895.
16:38:39,051 INFO  [paste.httpserver.ThreadPool] Cannot use kill_thread_limit as ctypes/killthread is not available
serving on http://127.0.0.1:5000

  create a controller

(mydevenv)[neo@development helloworld]$ paster controller hello
Creating /home/neo/helloworld/helloworld/controllers/hello.py
Creating /home/neo/helloworld/helloworld/tests/functional/test_hello.py

  http://192.168.3.9:5000/hello/index




3.1.2. Debian/Ubuntu




$ sudo apt-cache search pylons
$ sudo apt-get install python-pylons
$ paster create -t pylons helloworld
/usr/lib/pymodules/python2.6/pylons/templating.py:610: UserWarning: Unbuilt egg for setuptools [unknown version] (/usr/lib/python2.6/dist-packages)
Engine = entry_point.load()
Selected and implied templates:
Pylons#pylons  Pylons application template
Variables:
egg:      helloworld
package:  helloworld
project:  helloworld
Enter template_engine (mako/genshi/jinja2/etc: Template language) ['mako']:
Enter sqlalchemy (True/False: Include SQLAlchemy 0.5 configuration) [False]: True
Creating template pylons
Creating directory ./helloworld
Recursing into +package+
Creating ./helloworld/helloworld/
Copying __init__.py_tmpl to ./helloworld/helloworld/__init__.py
Recursing into config
Creating ./helloworld/helloworld/config/
Copying __init__.py_tmpl to ./helloworld/helloworld/config/__init__.py
Copying deployment.ini_tmpl_tmpl to ./helloworld/helloworld/config/deployment.ini_tmpl
Copying environment.py_tmpl to ./helloworld/helloworld/config/environment.py
Copying middleware.py_tmpl to ./helloworld/helloworld/config/middleware.py
Copying routing.py_tmpl to ./helloworld/helloworld/config/routing.py
Recursing into controllers
Creating ./helloworld/helloworld/controllers/
Copying __init__.py_tmpl to ./helloworld/helloworld/controllers/__init__.py
Copying error.py_tmpl to ./helloworld/helloworld/controllers/error.py
Recursing into lib
Creating ./helloworld/helloworld/lib/
Copying __init__.py_tmpl to ./helloworld/helloworld/lib/__init__.py
Copying app_globals.py_tmpl to ./helloworld/helloworld/lib/app_globals.py
Copying base.py_tmpl to ./helloworld/helloworld/lib/base.py
Copying helpers.py_tmpl to ./helloworld/helloworld/lib/helpers.py
Recursing into model
Creating ./helloworld/helloworld/model/
Copying __init__.py_tmpl to ./helloworld/helloworld/model/__init__.py
Copying meta.py_tmpl to ./helloworld/helloworld/model/meta.py
Recursing into public
Creating ./helloworld/helloworld/public/
Copying bg.png to ./helloworld/helloworld/public/bg.png
Copying favicon.ico to ./helloworld/helloworld/public/favicon.ico
Copying index.html_tmpl to ./helloworld/helloworld/public/index.html
Copying pylons-logo.gif to ./helloworld/helloworld/public/pylons-logo.gif
Recursing into templates
Creating ./helloworld/helloworld/templates/
Recursing into tests
Creating ./helloworld/helloworld/tests/
Copying __init__.py_tmpl to ./helloworld/helloworld/tests/__init__.py
Recursing into functional
Creating ./helloworld/helloworld/tests/functional/
Copying __init__.py_tmpl to ./helloworld/helloworld/tests/functional/__init__.py
Copying test_models.py_tmpl to ./helloworld/helloworld/tests/test_models.py
Copying websetup.py_tmpl to ./helloworld/helloworld/websetup.py
Copying MANIFEST.in_tmpl to ./helloworld/MANIFEST.in
Copying README.txt_tmpl to ./helloworld/README.txt
Copying development.ini_tmpl to ./helloworld/development.ini
Recursing into docs
Creating ./helloworld/docs/
Copying index.txt_tmpl to ./helloworld/docs/index.txt
Copying ez_setup.py to ./helloworld/ez_setup.py
Copying setup.cfg_tmpl to ./helloworld/setup.cfg
Copying setup.py_tmpl to ./helloworld/setup.py
Copying test.ini_tmpl to ./helloworld/test.ini
Running /usr/bin/python setup.py egg_info

  配置host监听地址

$ cd helloworld
$ vim development.ini
host = 0.0.0.0

  启动服务

$ paster serve --reload development.ini






3.2. config/routing.py




  url routing 做为静态化让所有后缀加上.html

(mydevenv)[neo@development helloworld]$ vim helloworld/config/routing.py
map.connect('/{controller}/{action}.html')
map.connect('/{controller}/{action}/{id}.html')




3.3. mako template




  http://www.makotemplates.org/


3.3.1. include





<%include file="header.html"/>
hello world
<%include file="footer.html"/>

  传递参数


<%include file="toolbar.html" args="current_section='members', username='ed'"/>




3.3.2. inherit





<%inherit file="base.html"/>

运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-370408-1-1.html 上篇帖子: 【Python】Matplotlib绘图库初探 下篇帖子: python脚本监控网站状态
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表