首页 > 代码库 > Django官方文档学习

Django官方文档学习

Django 1.10官方文档:https://docs.djangoproject.com/en/1.10/intro/tutorial01/

 

1.查看django版本

  python -m django --version

2.创建项目

  django-admin startproject mysite

3.调试工程

  python manage.py runserver [8080/0.0.0.0:8000]

4.创建APP

  python manage.py startapp polls

5.编辑APP视图(polls/views.py)

from django.http import HttpResponsedef index(request):    return HttpResponse("Hello, world. You‘re at the polls index.")

6.编辑APP链接(polls/urls.py)

from django.conf.urls import urlfrom . import viewsurlpatterns = [    url(r^$, views.index, name=index),]

7.编辑工程urls.py

# mysite/urls.pyfrom django.conf.urls import include, urlfrom django.contrib import adminurlpatterns = [    url(r^polls/, include(polls.urls)),    url(r^admin/, admin.site.urls),]

按照上面的流程就可以做出一个helloworld网页了

 

Django官方文档学习