K
K
Kirill3122020-12-24 22:25:12
Django
Kirill312, 2020-12-24 22:25:12

How to fix decorator related bug in django?

Good afternoon! I started to study django and I can't figure out decorators in any way... I can't find anything on the Internet. In general, I would like all get requests to display a void, and all others to display an error 405 The code is below. Thanks in advance!

from django.shortcuts import render
from django.http import HttpResponse
from django.template import loader
from django.views.decorators.http import require_http_methods, require_GET
# Create your views here.

def index(response):
     return HttpResponse('')
@require_http_methods(['GET'])
def req(request):
    return HttpResponse()

@require_http_methods(['POST'])
def req(request):
     return HttpResponse(staus = 405)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dr. Bacon, 2020-12-24
@bacon

I can't find anything on the Internet.
https://docs.djangoproject.com/en/3.1/intro/

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question