看完了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.



评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值