Home » Python » python – exchange data between different templates django-Exceptionshub

python – exchange data between different templates django-Exceptionshub

Posted by: admin February 24, 2020 Leave a comment

Questions:

I am new to django and on my course to learn django, i am facing a issue.

  • MY CURRENT GOAL:
    Take input from homepage(say localhost:8000/) in my app and display result to other webpage say (localhost:8000/result/)

  • WHAT I HAVE BEEN ABLE TO ACHIEVE:
    I was able to get input from homepage.html(localhost:8000/) using request.POST.get(‘widgetName’) in views.py under the function which is rendering homepage.html. I want to pass the data to another function in same views.py which renders resultpage.html(localhost:8000/result/)

here is how my views.py file looks

from django.shortcuts import render

# Create your views here.
def resultPageFunction(request):
    return render(request, "resultPageTemplate/reultPage.html")


def mainPageFunction(request):
    if (str(request.method).lower() == "post"):
        query = request.POST.get('searchArea')
        print(query)

    return render(request, "mainPageTemplate/homePage.html")

I am able to capture my input in query variable.
Currently i am working with raw HTML and not using django forms.
Thanks in advance.

How to&Answers:

Hard to help without seeing your views.py etc.