Добавил:
Upload Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
pyramid.pdf
Скачиваний:
11
Добавлен:
24.03.2015
Размер:
3.82 Mб
Скачать

37.3. INSTALLATION

37.3.6 Initializing the Database

We need to use the initialize_tutorial_db console script to initialize our database.

Type the following command, make sure you are still in the tutorial directory (the directory with a development.ini in it):

On UNIX:

$ ../bin/initialize_tutorial_db development.ini

On Windows:

c:\pyramidtut\tutorial> ..\Scripts\initialize_tutorial_db development.ini

The output to your console should be something like this:

2011-11-26

14:42:25,012 INFO

[sqlalchemy.engine.base.Engine][MainThread]

 

 

 

PRAGMA table_info("models")

 

2011-11-26

14:42:25,013 INFO

[sqlalchemy.engine.base.Engine][MainThread] ()

2011-11-26

14:42:25,013 INFO

[sqlalchemy.engine.base.Engine][MainThread]

CREATE TABLE models (

 

 

id INTEGER NOT NULL,

 

 

name VARCHAR(255),

 

 

value INTEGER,

 

 

PRIMARY KEY (id),

 

 

UNIQUE (name)

 

 

)

 

 

 

2011-11-26 14:42:25,013 INFO

[sqlalchemy.engine.base.Engine][MainThread] ()

2011-11-26 14:42:25,135 INFO

[sqlalchemy.engine.base.Engine][MainThread]

 

 

COMMIT

2011-11-26 14:42:25,137 INFO

[sqlalchemy.engine.base.Engine][MainThread]

 

 

BEGIN (implicit)

2011-11-26 14:42:25,138 INFO

[sqlalchemy.engine.base.Engine][MainThread]

 

 

INSERT INTO models (name, value) VALUES (?, ?)

2011-11-26 14:42:25,139 INFO

[sqlalchemy.engine.base.Engine][MainThread]

 

 

(u’one’, 1)

2011-11-26 14:42:25,140 INFO

[sqlalchemy.engine.base.Engine][MainThread]

 

 

COMMIT

 

 

 

 

Success! You should now have a tutorial.db file in your current working directory. This will be a SQLite database with a single table defined in it (models).

447

37. SQLALCHEMY + URL DISPATCH WIKI TUTORIAL

37.3.7 Starting the Application

Start the application.

On UNIX:

$ ../bin/pserve development.ini --reload

On Windows:

c:\pyramidtut\tutorial> ..\Scripts\pserve development.ini --reload

If successful, you will see something like this on your console:

Starting subprocess with file monitor

Starting server in PID 8966.

Starting HTTP server on http://0.0.0.0:6543

This means the server is ready to accept requests.

At this point, when you visit http://localhost:6543/ in your web browser, you will see the generated application’s default page.

One thing you’ll notice is the “debug toolbar” icon on right hand side of the page. You can read more about the purpose of the icon at The Debug Toolbar. It allows you to get information about your application while you develop.

37.3.8 Decisions the alchemy Scaffold Has Made For You

Creating a project using the alchemy scaffold makes the following assumptions:

you are willing to use SQLAlchemy as a database access tool

you are willing to use url dispatch to map URLs to code.

latex-note.png

Pyramid supports any persistent storage mechanism (e.g. object database or filesystem files, etc). It also supports an additional mechanism to map URLs to code (traversal). However, for the purposes of this tutorial, we’ll only be using url dispatch and SQLAlchemy.

448

Соседние файлы в предмете [НЕСОРТИРОВАННОЕ]