django初体验
创建项目
$ django-admin.py startproject myblog
$ cd myblog/
$ tree
.
├── manage.py
└── myblog
├── __init__.py
├── settings.py
├── urls.py
└── wsgi.py
manage.py - 项目的命令管理器
$ python manage.py runserver
Validating models...
0 errors found
April 21, 2020 - 14:21:57
Django version 1.6.11, using settings 'myblog.settings'
Starting development server at http://127.0.0.1:8000/
Quit the server with CONTROL-C.
这样就可以访问网站了
项目下创建应用
myblog$ python manage.py startapp blog
myblog$ tree -I *.pyc # 不列出pyc文件
.
├── blog
│ ├── __init__.py
│ ├── admin.py
│ ├── models.py
│ ├── tests.py
│ └── views.py
├── manage.py
└── myblog
├── __init__.py
├── settings.py
├── urls.py
└── wsgi.py
一定记得在settings.py中把新创建的应用加入你刚刚创建的应用。
编写传说中的Hello World
编写blog/views.py,添加以下内容:
修改myblog/urls.py
启动服务器,Hello world就完成了
$ python manage.py runserver