首页 > Web开发 > 详细

Django 学习笔记 关于URL

时间:2016-01-10 15:37:15      阅读:221      评论:0      收藏:0      [点我收藏+]
from django.conf.urls import include, url
from django.contrib import admin
from polls import views
urlpatterns = [
    url(r‘^admin/‘, include(admin.site.urls)),
    url(r‘^polls/$‘,views.index,name=‘index‘),
    
    url(r‘^polls/(?P<question_id>[0-9]+)/$‘,‘polls.views.detail‘),
    url(r‘^polls/(?P<question_id>[0-9]+)/results/$‘,views.results,name=‘results‘),
    url(r‘^polls/(?P<question_id>[0-9]+)/vote/$‘,views.vote,name=‘vote‘),
   
]

views.py 定义方法

from django.shortcuts import render
from django.http import HttpResponse
# Create your views here.

def index(request):
	return HttpResponse("hello django, you‘re at the polls index.")

def detail(request,question_id):
	return HttpResponse("you are looking at question %s."% question_id)

def results(request,question_id):
	reponse = "you are looking at the results of question %s."
	return HttpResponse(reponse%question_id)

def vote(request,question_id):
	return HttpResponse("you are voting on question %s."% question_id)

URL设置中 regular expression是一个比较重要的玩意儿 这个得学习好 友情链接:http://deerchao.net/tutorials/regex/regex.htm

 

Django 学习笔记 关于URL

原文:http://www.cnblogs.com/magicpower/p/5118383.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!