1 django 模块 2 3 一 安装: 4 5 方法一: 6 (在 JetBrains PyCharm 2017.2 软件的) 设置 (里找到) 项目:python +(添加) 7 (搜索) django Install package 8 9 方法二: 10 在WIN操作系统里的CMD里执行 11 c:> d: 12 d:> cd D:Program FilesPython3Scripts 13 #d:> cd D:Program FilesPython3Scripts#根据软件的目录去安装 14 15 pip3 install django 16 或 17 python -m pip install django 18 19 二 添加环境变量 20 在WIN操作系统里的CMD里执行 21 c:> d: 22 d:> cd D:Program FilesPython3Scripts 23 D:Program FilesPython3Scripts> dir 24 D:Program FilesPython3Scripts> django-admin startproject mysite 25 #D:Program FilesPython3Scripts> django-admin startproject 名称自定 26 D:Program FilesPython3Scripts> cd mysite 27 D:Program FilesPython3Scriptsmysite> python manage.py runserver 127.0.0.1:8000 28 29 打开浏览器 输入: 127.0.0.1:8000 30 31 #如果出错要添加系统环境变量 32 33 控制面板系统和安全系统 34 高级系统设置 35 高级 36 环境变量 37 系统变量(S) 38 path C:WINDOWS...... 39 40 变量名(N): path 41 变量值(V): ;D:Program FilesPython3Scripts;D:Program FilesPython3 42 43 44 45 46 三、创建DJango工程 47 在WIN操作系统里的CMD里执行 48 c:> e: 49 e:> django-admin startproject laoniu 50 e:> cd laoniu 51 e:laoniu> python manage.py 52 #运行不成功就添加环境变量 53 e:laoniu> python manage.py runserver 127.0.0.1:8001 54 #e:laoniu> python manage.py runserver 网址自己定义 55 56 57 58 mysite 59 -mysite #对整个程序进行配置 60 -init 61 -settings #配置文件 62 -url #URL对应关系 63 -wsgi #遵循WSIG规范,uwsgi +nginx 64 -manage.py #管理Django程序: 65 -python manage.py 66 -python manage.py startapp xx 67 -python manage.py makemigrations 68 -python manage.py migrate
创建DJango工程
在WIN操作系统里的CMD里执行
在WIN操作系统里的CMD里执行 c:> e: e:> django-admin startproject laoniu e:> cd laoniu e:laoniu> python manage.py
在JetBrains PyCharm 2017.2里找到E:laoniu打开
在E:laoniu里创建文件夹 xiaoniu
在xiaoniu 创建 s1.py
1 from django.shortcuts import HttpResponse 2 3 def index(requet): 4 return HttpResponse("一米八大高个")
修改E:laoniuaoniu的 urls.py
1 """laoniu URL Configuration 2 3 The `urlpatterns` list routes URLs to views. For more information please see: 4 https://docs.djangoproject.com/en/1.11/topics/http/urls/ 5 Examples: 6 Function views 7 1. Add an import: from my_app import views 8 2. Add a URL to urlpatterns: url(r'^$', views.home, name='home') 9 Class-based views 10 1. Add an import: from other_app.views import Home 11 2. Add a URL to urlpatterns: url(r'^$', Home.as_view(), name='home') 12 Including another URLconf 13 1. Import the include() function: from django.conf.urls import url, include 14 2. Add a URL to urlpatterns: url(r'^blog/', include('blog.urls')) 15 """ 16 from django.conf.urls import url 17 from django.contrib import admin 18 19 20 from xiaoniu import s1 21 urlpatterns = [ 22 url(r'^admin/', admin.site.urls), 23 url(r'^index/', s1.index), 24 ]
在WIN操作系统里的CMD里执行
e:laoniu> python manage.py runserver 127.0.0.1:8001
#e:laoniu> python manage.py runserver 网址自己定义
#运行不成功就添加环境变量