推荐学习书目
Learn Python the Hard Way
Python Sites
PyPI - Python Package Index
http://diveintopython.org/toc/index.html
Pocoo
值得关注的项目
PyPy
Celery
Jinja2
Read the Docs
gevent
pyenv
virtualenv
Stackless Python
Beautiful Soup
结巴中文分词
Green Unicorn
Sentry
Shovel
Pyflakes
pytest
Python 编程
pep8 Checker
Styles
PEP 8
Google Python Style Guide
Code Style from The Hitchhiker's Guide
SimbaPeng
V2EX  ›  Python

Django 怎么限制 url 的请求方式?类似 flask 的 app.route('/', methods=['POST'])

  •  
  •   SimbaPeng · Dec 15, 2017 · 4428 views
    This topic created in 3076 days ago, the information mentioned may be changed or developed.
    7 replies    2017-12-15 20:43:46 +08:00
    myyou
        1
    myyou  
       Dec 15, 2017
    django rest framework 有类似 flask 写法,也可以通过在 View 类定义请求方法来限制
    manzhiyong
        3
    manzhiyong  
       Dec 15, 2017
    你不在 view 里写 post 接收方法不就完了
    vZexc0m
        4
    vZexc0m  
       Dec 15, 2017
    ```
    @require_http_methods(['GET'])
    ```
    iiduce
        5
    iiduce  
       Dec 15, 2017
    view 里:

    if request.method == 'POST':
    post = request.POST
    ...
    Nick2VIPUser
        6
    Nick2VIPUser  
       Dec 15, 2017
    ```
    class TestView(View):
    def get(self, request):
    ......
    def post(self, request):
    ......
    ```
    ZnZt
        7
    ZnZt  
       Dec 15, 2017
    from django.views.decorators.http import require_POST, require_GET

    @require_GET
    def query():
    pass

    @require_POST
    def add():
    pass
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   5487 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 54ms · UTC 08:56 · PVG 16:56 · LAX 01:56 · JFK 04:56
    ♥ Do have faith in what you're doing.