注意,方法名必须大写。
require_GET()
只允许视图接受GET方法的装饰器。
@require_GET
def my_view(req):
print req.get_full_path()
return HttpResponse(status=202)
import requests
r = requests.get('http://192.168.137.3:9000/my_view/')
print(r.status_code)
C:Python27python.exe C:/Users/TLCB/PycharmProjects/untitled/templates/a12.py
202
import requests
r = requests.post('http://192.168.137.3:9000/my_view/')
print(r.status_code)
Method Not Allowed (POST): /my_view/
[15/Jan/2018 17:43:24] "POST /my_view/ HTTP/1.1" 405 0
实现了装饰器的功能