python - Django upload file : test request == POST or use decorator? -


i've read in django doc :

note request.files contain data if request method post

in example given :

def upload_file(request):     if request.method == 'post': 

i've read before can use decorator of django :

@require_http_methods(["get", "post"]) def my_view(request):     # can assume or post requests make far 

even 1 called @require_post().

it's question syntax , want know :

  1. if use decorator, stop function before execution if i'm not requesting post ?
  2. if 1) true, isn't decorators option 'python cool' ?

thanks in advance.

besta

the decorators in django.views.decorators.http can used restrict access views based on request method. these decorators return django.http.httpresponsenotallowed if conditions not met.

view decorators

as 2, if request.method == 'post' fine , used in function based views.


Comments

Popular posts from this blog

How has firefox/gecko HTML+CSS rendering changed in version 38? -

android - CollapsingToolbarLayout: position the ExpandedText programmatically -

Listeners to visualise results of load test in JMeter -