- 在磁盘中找到需要存放项目代驾的目录,进入该目录(本机为: /Downloads/All)
- 输入Django创建项目命令:django-admin startproject mysite,此时在目录下会创建一个名为“mysite”的文件夹
- 进入mysite文件夹,查看目录中文件清单
mysite/
manage.py
mysite/
__init__.py
settings.py
urls.py
wsgi.py
- 清单详解
- manage.py:命令行管理工具集,用于与Django项目的交互管理
- __init__.py:空文件,用于通知python这个目录是一个Python项目
- settings.py:设置和配制Django项目
- urls.py:内容分发器,用于配制Django中的站点
- wsgi.py:用于网关部署配制
- 使用默认数据库sqlite3,创建数据库及表结构:python manage.py migrate
➜ mysite python manage.py migrate
Operations to perform:
Synchronize unmigrated apps: staticfiles, messages
Apply all migrations: admin, contenttypes, auth, sessions
Synchronizing apps without migrations:
Creating tables...
Running deferred SQL...
Installing custom SQL...
Running migrations:
Rendering model states... DONE
Applying contenttypes.0001_initial... OK
Applying auth.0001_initial... OK
Applying admin.0001_initial... OK
Applying contenttypes.0002_remove_content_type_name... OK
Applying auth.0002_alter_permission_name_max_length... OK
Applying auth.0003_alter_user_email_max_length... OK
Applying auth.0004_alter_user_username_opts... OK
Applying auth.0005_alter_user_last_login_null... OK
Applying auth.0006_require_contenttypes_0002... OK
Applying sessions.0001_initial... OK
- 启动服务器:python manage.py runserver
➜ mysite python manage.py runserver
Performing system checks... System check identified no issues (0 silenced).
November 22, 2015 - 13:56:37
Django version 1.8.6, using settings 'mysite.settings'
Starting development server at http://127.0.0.1:8000/
Quit the server with CONTROL-C.
- 在浏览器中输入地址:http://127.0.0.1:8000/,若页面显示正确,则项目创建成功
- 修改启动端口:python manage.py runserver 8001
- 修改启动IP及端口:python manage.py runserver 0.0.0.0:8001
- 至此,第一个简单的Django项目创建成功了