Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

179
Views
Acess context from request in Django

How can we access the context passed in template in method views?

urls.py

urlpatterns = [
    path('', views.method_A, name='first_view'),
    path('method_B', views.method_B, name='second_view'),
]
def method_A(request):
    context = {"name":"sample"}
    html_template = loader.get_template('some_template.html')
    return HttpResponse(html_template.render(context, request))

Template as

<div>
   {{name}}
   <a href="method_B">Redirect</a>
</div>
def method_B(request):
    # Here how to get context which was present earlier
    context = {"second":"second"}
    html_template = loader.get_template('template_B.html')
    return HttpResponse(html_template.render(context, request))

How we can get context in method based views in django.? So that it can be used in another templates.

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

You can store as a session variable.

Views

def method_A(request):
    html_template = loader.get_template('some_template.html')
    request.session['my_context'] = 'Example' #Setting Cookie
    return HttpResponse(html_template.render(context, request))

def method_B(request):
    # Here how to get context which was present earlier
    my_context = request.session.pop('my_context', None) # Getting Cookie
    html_template = loader.get_template('template_B.html')
    return HttpResponse(html_template.render(context, request))
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!