Quixote

来自开放百科 - 灰狐
2012年10月28日 (日) 03:50Allen (讨论 | 贡献)的版本

(差异) ←上一版本 | 最后版本 (差异) | 下一版本→ (差异)
跳转到: 导航, 搜索
天涯何处无芳草,何必单恋一只花了

Quixote is yet another framework for developing Web applications in Python.

对于robust, quixote是经过大规模实际应用检验的, douban.com的主要动力就是它.

在放弃使用Zope后,MEMS Exchange 决定开发 Quixote

若使用 apache, 请事先安装 mod_pythonmod_scgi

目录

在线演示

http://demo.huihoo.com/quixote

安装指南

获得 quixote http://quixote.python.ca/releases/Quixote-2.4.tar.gz
tar zxvf Quixote-2.4.tar.gz
cd Quixote-2.4 

python -c "import os, quixote; print os.path.dirname(quixote.__file__)"  // 检查是否已有quixote安装
python setup.py install  // quixote 安装到 :/usr/lib/python2.3/site-packages/quixote 
若出现 error: invalid Python installation: unable to open /usr/lib/python2.3/config/Makefile (No such file or directory)
请安装 #apt-get install python2.3-dev
或 /usr/local/lib/python2.4/site-packages/quixote/server/  // 使用了 Python 2.4
或 /usr/local/lib/python2.5/site-packages/quixote/server/ // 使用了 Python 2.5
demo 被安装到 /usr/local/lib/python2.4/site-packages/quixote/demo/
python demo/mini_demo.py
http://localhost:8080
python server/simple_server.py
http://localhost:8080
python server/simple_server.py --port 4000
http://localhost:4000

通过mod_python与Apache的整合

#apt-get install apache2-dev 安装 apxs2 , apxs 针对 Apache 1.x

获得 http://www.apache.org/dist/httpd/modpython/mod_python-3.2.10.tgz 
./configure --with-apxs=/usr/bin/apxs2
make
make install
vi /etc/apache2/sites-enabled/000-default
相关细节: /usr/lib/python2.3/site-packages/quixote/server/mod_python_handler.py
   LoadModule python_module /usr/lib/apache2/modules/mod_python.so
   <LocationMatch "^/quixote(/|$)">
       SetHandler python-program
       PythonHandler quixote.server.mod_python_handler
       PythonOption quixote-publisher-factory quixote.demo.create_publisher
       PythonInterpreter quixote.demo
       PythonDebug On
   </LocationMatch>

/etc/init.d/apache2 restart
http://localhost/quixote

Windows用户

cd Quixote-2.4
修改 setup.py 
build_extensions = True
python setup.py build_ext --compiler=mingw32 install

通过scgi

http://www.mems-exchange.org/software/scgi/
python setup.py install
LoadModule scgi_module /usr/local/lib/python2.3/site-packages/mod_scgi.so
<Location "/">
    SetHandler scgi-handler // Apache 2.0 need, Apache 1.3 don't need
    SCGIServer 1localost:3000
    SCGIHandler On
</Location>

Quixote Sample

touch miniqx.py

#!/usr/bin/env python
from quixote.publish import Publisher
from quixote.directory import Directory

class RootDirectory(Directory):
    _q_exports = [, 'hello']
    def _q_index(self):
    return <html>
              <body>
               Simple Quixote Server
               A <a href="hello">link</a>.
</body> </html> def hello(self): return '<html><body>Hello world!

<a href="/">Home</a></body></html>'
def create_publisher():
    return Publisher(RootDirectory(),
    display_exceptions='plain')
if __name__ == '__main__':
    from quixote.server.simple_server import run
    print 'creating demo listening on http://192.168.1.3:8082/'
    run(create_publisher, host='192.168.1.3', port=8082) 

python minipx.py

http://192.168.1.3:8082

Quixote Toolkit

How Quixote Works

核心原则

Quixote is built on four core principles:

  • Publishing function results: Quixote's main job is using a URL to look up a Python callable (e.g., a function or method) and put its results on the web.
  • The URL is part of the user interface, and the organization of source code and URL-space should roughly correspond.
  • Embedding HTML in Python is cleaner and easier than embedding Python in HTML. // 类似 Java Servlet
  • No magic: when Quixote can't figure out what to do, it refuses to guess the programmer's intent, preferring to raise an exception instead.

Web Interface

The web interface to SPLAT! is implemented in the splat.web package, with the following modules:

  • splat.web.util (splat/web/util.ptl)
  • splat.web.index (splat/web/index.ptl)
  • splat.web.bug_ui (splat/web/bug_ui.ptl)
  • splat.web.prefs (splat/web/prefs.ptl)

In fact, there are many useful analogies between a traditional filesystem-based web server (such as Apache) and Quixote's Python-centric way of building a web site.:

Table 1
Filesystem (e.g., Apache) Quixote
directory Python namespace (module, package, ...)
file Python callable object (function, method, ...)
index.html _q_index()
file exists, is readable callable object exists, is in _q_exports

相关项目

成功应用

more apps : http://www.mems-exchange.org/software/quixote/apps.html

相关链接

Comment-32x32.png

<discussion>characters_max=300</discussion>

分享您的观点
个人工具
名字空间

变换
操作
导航
工具箱