A
A
Akkountven2022-04-17 20:56:09
Django
Akkountven, 2022-04-17 20:56:09

How to call a function in Django?

How can I call a function in django if it has a request argument?

def A(request):
    . . .
    get = json.loads(request.body)

A() # TypeError: A() missing 1 required positional argument: 'request'
A(request) # AttributeError: module 'django.http.request' has no attribute 'body'

Errors are commented in the code, what do I need to do?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
Dr. Bacon, 2022-04-17
@bacon

If it is a view, then it is not intended to be called on its own.

A
Alexander Nesterov, 2022-04-17
@AlexNest

I'm wondering - before you ask a question, did you read at least some material on django? I doubt it, because such things are described in the first lesson / chapter !
Obviously, passing the request object to it.
How to do it?
B.1 Add an appropriate route for it in urls.py
B.2 Call it in a function that is specified in an existing route.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question