django学习之二在浏览器上完美计算两个数的和

django学习之二在浏览器上完美计算两个数的和

 

1.编写代码views.py

# -*- coding: utf-8 -*-
from django.http import HttpResponse

def index(request):
    return HttpResponse(u'<h3>欢迎来到陈建文的学习基地!')

def add1(request):
    a = request.GET['a']
    b = request.GET['b']
    c = int(a)+int(b)
    return HttpResponse(str(c))

def add2(request,a,b):
    c = int(a)+int(b)
    return HttpResponse(str(c))

2.编写代码urls.py

from django.conf.urls import url
from django.contrib import admin
from learn import views as learn_views

urlpatterns = [
    url(r'^admin/', admin.site.urls),
    url(r'^$',learn_views.index),
    url(r'^add1/$',learn_views.add1,name='add1'),
    url(r'^add2/(\d+)/(\d+)/$',learn_views.add2,name='add2')
]

3.得到两种计算方式

===================大功告成===================

===================QQ1071179133===================

posted @ 2017-07-21 19:01  chenjianwen  阅读(202)  评论(0编辑  收藏  举报