D
D
Domohod2022-02-17 18:23:24
Django
Domohod, 2022-02-17 18:23:24

How to pass context from one template to another (Django)?

I need to be able to take variables from the view context into the template it doesn't render, example:

def view(request):
    context = 1
    return render(request, 'file.html', {'context': context})

def view_need(request):
    return render(request, 'other.html')


Here, context will get the file file.html, however, I need to use this variable in other.html, while the context cannot be written in view_need. How can I do that?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander Nesterov, 2022-02-17
@AlexNest

context cannot be set in view_need.

Looks like perversion and stringing an owl on a globe. At least in the example you provided - there is no reason not to add context.
If, nevertheless, for some reason it is necessary to do this, use the session (in some cases it is possible and necessary to do otherwise, but I'm not sure that this is the case).

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question