django - Could not pass value in URL query string using Dajngo and Python -
i need 1 help. need pass session id in url query string after login using dajngo , python in case getting error. explaining code below.
def loginsave(request): """this function helps login user """ if request.method == 'post': password = request.post.get('pass') uname = request.post.get('uname') per = user.objects.all().filter( q(password__icontains=password) & q(uname__icontains=uname)).count() if per > 0: user = user.objects.filter( q(password__icontains=password) & q(uname__icontains=uname)) use in user: uid = use.id user_name = use.uname request.session['id'] = uid request.session['sess'] = dict(dt=str(datetime.now()), value='session') request.session['sess_id'] = 'abcd1234' return render(request, 'bookingservice/home.html', {'count': per, 'username': user_name}) else: return render(request, 'bookingservice/login.html', {})
this login function here creating session id , need pass on url. menu list given below.
<a href="{% url 'home' %}?token={{request.session["sess_id"]}}">home</a> <a href="{% url 'booking' %}">add booking</a> <a href="{% url 'personal' %}">add personal info</a>
i doing here getting following error.
exception value: not parse remainder: '["sess_id"]' 'request.session["sess_id"]'
here need after login session id should come on every page url. please me.
change
{{request.session["sess_id"]}}
to
{{ request.session.sess_id }}
usually template language of django works way. here dot in variable name signifies lookup.when template system encounters dot in variable name, tries following lookups, in order:
dictionary lookup. example: request.session["bar"] attribute lookup. example: request.session.bar list-index lookup. example: request.session[bar]
you can find more @ docs
Comments
Post a Comment