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===================
一些事情一直在干,说不定以后就结果了呢
本文来自博客园,作者:chenjianwen,转载请注明原文链接:https://www.cnblogs.com/chenjw-note/articles/7219255.html