Pyramid getting start

Source: Internet
Author: User
Tags virtualenv
1 Install pyramid

We recommend using virtualenv to install pyramid:

$ CD/path/to/Your/virtual/env
$ Virtualenv-no-site-packages pyramid
$ CD pyramid $ bin/PIP install pyramid

Many things are installed:

Library Purpose
Pyramid Web Framework
Chameleon Template
Mako Another Template
Webob Wsgi framework
Repoze. LRU Cache support
Zope. Interface Zca interface framework
Zope. deprecation The "not recommended" function can be used for modules, classes, functions, methods, and attributes.
Venusian Deferring decorator
Translationstring Internationalization
Pastedeploy Wsgi Application Deployment Tool
Markupsafe Markup Language Support

 

If you are using pyramid 1.3a7, you also need to install waitress (A wsgi server under the pylons project ):

$ Bin/PIP install waitress

 

2 Create a project

Pyramid supports three types of engineering templates:

 

Engineering Template Description
Starter Basic Web Framework
Zodb Implement URL ing using roaming (traversal) and use zodb for persistence
Alchemy Use URL dispatch to implement URL ing and use sqlalchemy for persistence

If you have used Zope, you will be familiar with choosing a zodb template, but if not, try alchemy because sqlalchemy is almost the de facto standard of Python Orm.

To create a project using the alchemy Project template, run the following command:

$ Pyramid/bin/pcreate-s alchemy myproject

Pyramid creates the following directory structures and files:

 

 

Myproject/── changes.txt ── manifest. in ├ ── readme.txt ── development. INI ├ ── myproject │ ── _ init __. PY │ ── models. PY │ ── scripts │ ── _ init __. PY │ ── initializedb. PY │ ── static │ ── favicon. ICO │ ├ ── footerbg.png │ ├ ── headerbg.png │ ie── ie6.css │ ├ ── middlebg.png │ ├ ── pylons.css │ ── pyramid-small.png │ ── pyramid.png │ ── transparent.gif │ ── templates │ └ ── mytemplate.pt │ ├ ── tests. PY │ ── views. PY ── production. INI ── setup. CFG ── setup. PY

 

 

Take a look at the myproject/directory. This is a typical Python project release structure. Some of the files are as follows:

File Description
Changes.txt Change description, which can be in restructuredtext format
Manifest. In Decide which files are packedCodeWill be released
Readme.txt Project description, written in restructuredtext format.
Development. ini Pastedeploy configuration file for development stage
Production. ini Pastedeploy configuration file for Release Phase
Setup. cfg and setup. py Setuptools configuration file and execution File

If you need to extend this structure, you can refer to the directory structure of the python open-source project.

 

A python package: myproject will be created under the myproject Directory, which is to place the pyramid application. If you have used Django, you will find that the directory structure is similar to that of Django. Brief description:

 

File/directory Description
_ Init _. py Python package initialization script. The pyramid framework places a main function in it as an entry to some commands (such as pserve, pshell, pviews, and so on.
Models. py Model Code. When using the alchemy Project template, this file contains the basic code of sqlalchemy and an example of a model class.
Scripts Some development script tools
Static Web static files
Templates Template directory
Tests. py Unit test code
Views. py View code

 

 

3 Run

Three steps are required for running: test, deployment, and run.

$ Python setup. py test-Q

$ Python setup. py develop

$ Pserve development. ini

If this is the first time you run a web application, you may need to initialize the database:

$ Initialize_myproject_db development. ini

 

Note: The Python, pserve, and are all scripts under/path/to/Your/virtual/ENV/pyramid/bin.

 

After running with pserve, you can see the web application in the browser: http: // 0.0.0.0: 6543

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.