看完了Writing your first Django app, part 1,我的筆記(1)

談一下感想

       大部分時間花在配置環境上了,很痛苦、很麻煩,自己的linux水平太低了,許多東西都不太理解,僅僅是照着文檔來安裝,一旦出了一點問題,連變通的辦法都沒有 。

筆記

Writing your first Django app, part 1
-----------------------------------------
Creating a project
django-admin.py startproject mysite

The development server

Database setup
這部分真夠麻煩,我安裝mysql遇到了好多問題呢,Linux要好好學習才行。問題詳見blog。
運行python manage.py syncdb
後,我建立了一個超級帳戶,用戶名develop,密碼develop
以下是自動建立的表
mysql> show tables;
+----------------------------+
| Tables_in_mysite           |
+----------------------------+
| auth_group                 |
| auth_group_permissions     |
| auth_message               |
| auth_permission            |
| auth_user                  |
| auth_user_groups           |
| auth_user_user_permissions |
| django_content_type        |
| django_session             |
| django_site                |
+----------------------------+
10 rows in set (0.01 sec)

以上的工作完成後,所有的“project”環境就已經搭建完成

Creating models
"project"與"app"的關係
Projects vs. apps
What's the difference between a project and an app? An app is a Web

application that does something -- e.g., a weblog system, a database of

public records or a simple poll app. A project is a collection of

configuration and apps for a particular Web site. A project can contain

multiple apps. An app can be in multiple projects.

To create your app, make sure you're in the mysite directory and type

this command:

python manage.py startapp polls
That'll create a directory polls, which is laid out like this:

polls/
    __init__.py
    models.py
    views.py

This directory structure will house the poll application.
In our simple poll app, we'll create two models: polls and choices


Activating models
That small bit of model code gives Django a lot of information. With it,

Django is able to:

Create a database schema (CREATE TABLE statements) for this app.
Create a Python database-access API for accessing Poll and Choice

objects

Playing with the API
python manage.py shell
We're using this instead of simply typing "python", because manage.py sets up the project's environment for you.

發佈了53 篇原創文章 · 獲贊 0 · 訪問量 11萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章