Build a Django environment and build a django Environment
Install Python 2.7.10
Download unzip Django Django-1.9.2.tar.gz
Cmd cd to the extract directory (***)
Python setup. py install
Check whether the installation is successful
Environment Variable
Path
C: \ Python27 \ Lib \ site-packages \ Django-1.9.2-py2.7.egg \ django \ bin;
C: \ Python27 \ Scripts
Create a project
Django-admin.py startproject mysite
Dir/B View
Start the server
Cd to mysite first
Manage. py runserver
Open web
127.0.0.1: 8000
View port usage netstat-ano
Kill Process
Manage. py runserver 8080 ~~~ Hemp eggs
Http://www.oschina.net/question/234345_54799
Http://www.ibm.com/developerworks/cn/linux/l-django/
Hello World
The page content is generated by view function. The URL is defined in URLconf.
1. Create a Project
Django-admin.py startproject mysite
2. Create an APP in the manage. py directory.
manage.py startapp polls
3. Create a View Function
Path: polls/view. py
from django.shortcuts import render# Create your views here.from django.http import HttpResponsedef index(request): return HttpResponse("HelloWorld")
4. Create URLconf
Polls/urls. py
from django.conf.urls import urlfrom . import viewsurlpatterns=[ url(r'^$',views.index,name='index'),]
Link to root URLconf
from django.conf.urls import include,urlfrom django.contrib import adminurlpatterns = [ url(r'^polls/',include('polls.urls')), url(r'^admin/', admin.site.urls),]
To call the view, we need to map it to a URL
Result:
Problems: