Django基于Pycharm开发之一【创建django工程】

Django的工程结构,可以通过pycharm里面,选择创建django工程来直接创建,也可以通过命令行通过pip来安装。

一.通过命令行安装的步骤

  1. Install Python.
  2. Install a Python Virtual Environment.
  3. Install Django.

查看官方的建议是,强烈建议安装python 3,但是我安装的是python2,看个人喜好。(Unless you have a very good reason to use Python 2 (e.g. legacy libraries), Python 3 is the way to go.)

安装完python后,请执行第4步。

     4.更新PIP(Python包管理器)

  >>>python -m pip install -U pip --->可能会出错,解决方案是删除PYTHON目录下相应旧包的安装文件,就可以安装新版本了

    5.安装PYTHON运行时环境

    >>>pip install virtualenv

   6.创建site

   >>>virtualenv env_mysite

   7.安装Django

  >>>pip install django==1.8.13  (可以直接指定版本号)

 8.创建解决方案(project)

 >>>django-admin startproject (关于这个些命令可以直接在安装后生成的sitepackage下的django->command下面查找到,所以不必每个命令都去记的)

9.创建APP

>>>django-admin startapp app_name 

10.数据库迁移,默认是不能访问adminsite的,因为还没有表

>>>python manage.py imgrate

(The migrate command looks at the INSTALLED_APPS setting and creates any necessary database tables according to the database settings in your settings.py file and the database migrations shipped with the app (we’ll cover those later). You’ll see a message for each migration it applies.)

从这句话中可以看到的是,迁移时产生的sql建表逻辑,来源于这边配置的app中的模块中的model

11.运行程序

cd到最外层的工程目录,执行:python manage.py runserver  可以看到启动时打开的端口号。

 

posted @ 2016-12-29 10:06  不卷轮子锅  阅读(225)  评论(0编辑  收藏  举报