Django
1.创建一个项目
linux :django-admin startproject helloword 创建项目helloword
2.开始一个工程
manage.py 文件
它是django工程中的总控制器
它是整个工程的入口程序
python manage.py help
3.开始一个工程
python manage.py runserver 0.0.0.0:8000
0.0.0.0任意IP都可以访问, 8000端口 , 默认端口80
4.开始一个app,写一个hello world
python manage.py startapp hello
编辑hello下的views
# -*- coding: utf-8 -*- from __future__ import unicode_literals from django.shortcuts import render from django.views import View from django.http import HttpResponse # Create your views here. class Hello(View): def get(self, request): message = 'hello world' return HttpResponse(message)
添加urls
from django.conf.urls import url from django.contrib import admin from hello import views urlpatterns = [ url(r'^admin/', admin.site.urls), url(r'^hello/', views.Hello.as_view()), url(r'^ces/(?P<name>[a-z]{3,8})'), # 命名参数 参数名指定为 name *括号 url(r'^hello1/([0-9]{4})/([0-9]{2})([0-9]{2})$', views.Hello1.as_view()), # 非命名参数([0-9]{4})/([0-9]{2})([0-9]{2}) 一个括号一个参数 def get(self, num1, num2, num3) 一一对应 ]
from django.conf.urls import url from django.contrib import admin from hello import views urlpatterns = [ url(r'^admin/', admin.site.urls), url(r'^hello/', views.Hello.as_view()),
url(r'^ces/?P<name>[a-z]{3,8}'), # 命名参数
url(r'^hello1/([0-9]{4})/([0-9]{2})([0-9]{2})$', views.Hello1.as_view()), # 非命名参数([0-9]{4})/([0-9]{2})([0-9]{2})
def get(self, num1, num2, num3) 一一对应
]