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 :
- if use decorator, stop function before execution if i'm not requesting post ?
- 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.
as 2, if request.method == 'post' fine , used in function based views.
Comments
Post a Comment