Django环境搭建

时间:2024-04-03 18:06:26

1.安装好Python 2.7.10

2.下载解压Django Django-1.9.2.tar.gz

  cmd cd到解压缩目录(***)

  python setup.py install

Django环境搭建

3.检测是否安装成功

import django

django.Version

print (django.__path__)  双下划线

Django环境搭建

P.S.环境变量

path:

C:\Python27\Lib\site-packages\Django-1.9.2-py2.7.egg\django\bin;

C:\Python27\Scripts

4.新建工程

django-admin.py startproject mysite

Django环境搭建

Django环境搭建

dir /b查看

Django环境搭建

5.启动服务器

先cd到mysite下

manage.py runserver

Django环境搭建

Django环境搭建

Django环境搭建

6.web打开

127.0.0.1:8000

查看端口占用netstat –ano

Django环境搭建

kill掉进程

Django环境搭建

纠错:manage.py runserver 8080~~~麻蛋Django环境搭建

Django环境搭建

相关参考资料

http://www.oschina.net/question/234345_54799

http://www.ibm.com/developerworks/cn/linux/l-django/


Hello World

页面的内容是靠view function(视图函数) 来产生,URL定义在 URLconf 中

1.新建Project

django-admin.py startproject mysite

2.新建APP,于manage.py一个目录

manage.py startapp polls

Django环境搭建

Django环境搭建

3.新建View函数

路径:polls/view.py

from django.shortcuts import render

# Create your views here.

from django.http import HttpResponse

def index(request):
return HttpResponse("HelloWorld")

4.新建URLconf

polls/urls.py

from django.conf.urls import url

from . import views

urlpatterns=[
url(r'^$',views.index,name='index'),]

链接到root URLconf

from django.conf.urls import include,url
from django.contrib import admin urlpatterns = [
url(r'^polls/',include('polls.urls')),
url(r'^admin/', admin.site.urls),
]

To call the view, we need to map it to a URL

结果:

Django环境搭建

遇到的问题:

Django环境搭建