Django 视图与网址进阶:
此文已经针对Django 2.0更新,适用于Django1.4-Django 2.0所有版本:
一,在网页上做加减法:
1.采用/add?a=5&b=5 这样GET方法进行
django-admin.py startproject zqxt_views
node2:/app/mysite/learn#cat views.py
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.shortcuts import render
from django.http import HttpResponse
# Create your views here.
from django.http import HttpResponse
def index(request):
return HttpResponse(u"欢迎光临 自强学堂!")
def add(request):
a = request.GET['a']
b = request.GET['b']
c = int(a)+int(b)
return HttpResponse(str(c))
node2:/app/mysite/learn#curl 'http://192.168.137.3:8000/add/?a=3&b=4'
7node2:/app/mysite/learn#