from django.conf.urls import url
from django.contrib import admin
from blog import views
urlpatterns = [
url(r'^admin/', admin.site.urls),
url(r'^blog/index/',views.index,name='index'),
url(r'^blog/add1/',views.add1,name='add1'),
url(r'^blog/add2/(\d+)/(\d+)/$',views.add2,name='add2')
========================================================
from django.shortcuts import render_to_response
from django.http import HttpResponse
from django.template import loader,Context
'''
def index(req):
t = loader.get_template('index.html')
c = Context({})
return HttpResponse(t.render(c))
'''
def index(req):
return render_to_response('index.html',{})
def add1(req):
a = req.GET['a']
b = req.GET['b']
c = int(a) + int(b)
return HttpResponse(str(c))
def add2(req,a,b):
c = int(a)+int(b)
return HttpResponse(str(c))
=========================================================
python manage.py shell
>>> from django.core.urlresolvers import reverse
>>> reverse('add2',args=(4,5))