One piece,是真正存在的。

此博客停更,新地址传送门:Yuanjie

Django-简单项目创建

  1. 在磁盘中找到需要存放项目代驾的目录,进入该目录(本机为: /Downloads/All)
  2. 输入Django创建项目命令:django-admin startproject mysite,此时在目录下会创建一个名为“mysite”的文件夹
  3. 进入mysite文件夹,查看目录中文件清单
    1. mysite/
          manage.py
          mysite/
              __init__.py
              settings.py
              urls.py
              wsgi.py
  4. 清单详解
    1. manage.py:命令行管理工具集,用于与Django项目的交互管理
    2. __init__.py:空文件,用于通知python这个目录是一个Python项目
    3. settings.py:设置和配制Django项目
    4. urls.py:内容分发器,用于配制Django中的站点
    5. wsgi.py:用于网关部署配制
  5. 使用默认数据库sqlite3,创建数据库及表结构:python manage.py migrate
    1. ➜  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
  6. 启动服务器:python manage.py runserver
    1. ➜  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.
  7. 在浏览器中输入地址:http://127.0.0.1:8000/,若页面显示正确,则项目创建成功
    1. 修改启动端口:python manage.py runserver 8001
    2. 修改启动IP及端口:python manage.py runserver 0.0.0.0:8001
  8. 至此,第一个简单的Django项目创建成功了

posted on 2015-11-22 22:01  One|Piece  阅读(733)  评论(0编辑  收藏  举报

导航