博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
8.2. Pylons
阅读量:7122 次
发布时间:2019-06-28

本文共 5058 字,大约阅读时间需要 16 分钟。

8.2.1. Getting Started with Pylons

8.2.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.iniStarting subprocess with file monitorStarting server in PID 26895.16:38:39,051 INFO  [paste.httpserver.ThreadPool] Cannot use kill_thread_limit as ctypes/killthread is not availableserving on http://127.0.0.1:5000

create a controller

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

http://192.168.3.9:5000/hello/index

8.2.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 templateVariables:  egg:      helloworld  package:  helloworld  project:  helloworldEnter template_engine (mako/genshi/jinja2/etc: Template language) ['mako']:Enter sqlalchemy (True/False: Include SQLAlchemy 0.5 configuration) [False]: TrueCreating template pylonsCreating 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.iniRunning /usr/bin/python setup.py egg_info

配置host监听地址

$ cd helloworld$ vim development.ini		host = 0.0.0.0

启动服务

$ paster serve --reload development.ini

8.2.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')

8.2.3. mako template

http://www.makotemplates.org/

8.2.3.1. include

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

传递参数

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

8.2.3.2. inherit

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

原文出处:Netkiller 系列 手札
本文作者:陈景峯
转载请与作者联系,同时请务必标明文章原始出处和作者信息及本声明。

你可能感兴趣的文章
设置Linux可以查看历史命令的执行时间
查看>>
ASP.NET之旅—再一次与ASP谋面
查看>>
CCToggleVisibility和CCPlace
查看>>
用ISA2006配置单网卡缓存服务器
查看>>
CSS预处理器之SASS用法指南
查看>>
开源下载工具
查看>>
OllyUni.dll
查看>>
VS2008远程调试
查看>>
Cracking the coding interview--Q2.2
查看>>
brew 中的时间格式转换
查看>>
读者来信与解答 1
查看>>
xdebug 安装及使用规则
查看>>
SharePoint 创建 Lookup 类型的Site Column解决跨站问题
查看>>
VS2010(2012)中使用Unit Testing进行单元测试
查看>>
onclick事件分析
查看>>
MySQL ALTER语法的运用方法 && 操作索引和字段
查看>>
UNIX网络编程读书笔记:poll函数
查看>>
《数据结构教程》(李春葆 主编)课后习题【2.4】
查看>>
英语应用文写作之感谢信
查看>>
[物理学与PDEs]第3章习题参考解答
查看>>