[Python] How to use Pyramid?
2014-03-04 11:59
344 查看
In this blog, i will tell you how to use Pyramid by codes.
''' The start point is the Configurator class.Use it to configure the routes and views, give application back to wsgi server finally. The class Configurator inherits many classes.It is a big mix and has great power. ''' from wsgiref.simple_server import make_server from pyramid.config import Configurator from pyramid.response import Response def hello(request): return Response("This is my small application") def page(request): return Response("This is another page") def main(): config = Configurator() config.add_route('hello', '/') config.add_route('test','/test') config.add_route(name="page",pattern="/page",view=page) config.scan('view') config.add_view(view=hello,route_name="hello") app = config.make_wsgi_app() return app if __name__ == '__main__': app = main() server = make_server('127.0.0.1', 8080, app) print ('Starting up server on http://localhost:8080') server.serve_forever()
相关文章推荐
- How to properly use relative or absolute imports in Python modules? - Stack Overflow
- How To Use Linux epoll with Python
- Seven Python Tools All Data Scientists Should Know How to Use
- [Python]How to use magic methods in Python?
- How to Install and Use Python Pip on Ubuntu 14.04 and pip install pytz
- how to use pandas in python
- how to use Decimal by default instead of float in python
- How to use Django with Apache and mod_python
- how to use python virtualenv on windows
- how to use linux epoll with python
- HOWTO Use Python in the web — Python v3.0.1 documentation
- How to use FTP in Python
- How-to use MySQL-python in Python
- How To Use Linux epoll with Python
- [gist]How to use Mock testing Python
- How To Use Linux epoll with Python
- [zz]How to use *args and **kwargs in Python
- how to use novaclient python api
- How To Use Linux epoll with Python
- How to use *args and **kwargs in Python