Explore Courses Blog Tutorials Interview Questions
0 votes
in Web Technology by (19.9k points)

When I navigate to my first view, the GET request is saved as a session variable.

def index(request):

if request.method == 'GET':

    symbol = request.GET.get('symbol', 'none')

    request.session['symbol'] = symbol

return render(request, 'backtests/yieldcurve.html', {'symbol' : symbol})

Then, when I navigate to another page via the sidebar, the GET request still shows up.

def yieldcurve(request):

    symbol = request.session.get('symbol', 'none')

    return render(request, 'backtests/yieldcurve.html', {'symbol' : symbol})

Yet, when I navigate back to the index from the sidebar, the GET request is not saved. Is there a way to do this?

1 Answer

0 votes
by (25.1k points)

Because whenever you go to index with a GET, you always overwrite whatever's saved in the session. If you have nothing in the GET request, you overwrite the session value with none.

You should probably check that the symbol is in request.GET and not in request.session before setting it.

Related questions

+1 vote
1 answer
0 votes
1 answer
0 votes
1 answer
0 votes
1 answer
Welcome to Intellipaat Community. Get your technical queries answered by top developers!

30.5k questions

32.5k answers


108k users

Browse Categories