我需要在使用Django和Python登錄後在URL查詢字符串中傳遞會話ID,但在我的情況下,我收到了一些錯誤。我在下面解釋我的代碼。無法在使用Django和Python的URL查詢字符串中傳遞值
def loginsave(request):
"""This function helps to login the 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))
for 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', {})
這是我的登錄功能,我在這裏創建會話ID,我需要通過URL傳遞它。我的菜單列表如下。
<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>
我這樣做,但在這裏我得到以下錯誤。
Exception Value:
Could not parse the remainder: '["sess_id"]' from 'request.session["sess_id"]'
在這裏,我需要登錄後,會話ID應該來每頁的URL。
其工作。謝謝。 – satya