url路由分发之include

url路由分发之include

 1 项目文件夹下的urls.py文件中的url写法:
 2     from django.conf.urls import url,include
 3     from django.contrib import admin
 4     from app01 import views
 5     urlpatterns = [
 6         # url(r‘^admin/‘, admin.site.urls),
 7         #首页
 8         url(r^$, views.base),
 9 
10         url(r^app01/, include(app01.urls)),
11 
12         url(r^app02/, include(app02.urls)),
13 
14     ]
15     
16 app01下urls.py内容写法
17     from django.conf.urls import url
18     from django.contrib import admin
19     from app01 import views
20     urlpatterns = [
21         # url(r‘^admin/‘, admin.site.urls),
22         url(r^$, views.app01base),
23         url(r^index/, views.index),
24     ]
25     
26 app02下urls.py内容写法   
27     from django.conf.urls import url
28     from django.contrib import admin
29     from app02 import views
30 
31     urlpatterns = [
32         # url(r‘^admin/‘, admin.site.urls),
33         url(r^$, views.app02base),
34         url(r^home/, views.home),
35 
36     ]

响应相关的方法

 1 HttpResponse  --- 回复字符串的时候来使用
 2 render --- 回复一个html页面的时候使用
 3 redirect -- 重定向
 4     示例:
 5     def login(request):
 6         if request.method == GET:
 7             return render(request,login.html)
 8         else:
 9             username = request.POST.get(username)
10             password = request.POST.get(password)
11             if username == taibai and password == dsb:
12                 # return render(request,‘home.html‘)
13                 return  redirect(/home/)  #重定向
14             else:
15                 return HttpResponse(滚犊子,赶紧去充钱!!!)
16 
17     #首页
18     def home(request):
19         return render(request,home.html)

请求相关的属性方法(request--HttpRequest对象)

 1 def index(request): #http相关请求信息---封装--HttpRequest对象
 2 
 3     if request.method == GET:
 4         print(request.body)  #获取post请求提交过来的原始数据
 5         print(request.GET)   #获取GET请求提交的数据
 6         # print(request.META)  # 请求头相关信息,就是一个大字典
 7         print(request.path) #/index/ 路径
 8         print(request.path_info) #/index/ 路径
 9         print(request.get_full_path())  #/index/?username=dazhuang&password=123
10         
11         return render(request,index.html)
12     else:
13         print(request.body)  # b‘username=dazhuang‘
14         print(request.POST) #获取POST请求提交的数据
15         return HttpResponse(男宾三位,拿好手牌!)

 

url路由分发之include

上一篇:smarty调用php常量


下一篇:WPF程序中App.Config文件的读与写