Reputation: 1658
if multiple users logs in and query for something at the same time, then how can i recognize which user queried for which thing.
i tried to make a group chat system. the idea is just to make a wall on which all users will post but the problem is how can i know which user requested to post if there r multiple users at same time.
my views.py-
def login(request):
if request.method == 'POST':
post = request.POST
u = user.objects.get(username = post['username'])
if post['password'] == u.password:
request.session['username'] = u.username
return redirect('wall')
else:
return render(request, 'wall/login_page.html')
def wall(request):
if request.method == 'POST':
post = request.POST
if 'logout' in post:
del request.session['username']
return redirect('home')
elif 'post' in post:
posted_by = request.session.get('username', '')
post_content = post['post_text']
post_id = posted_by+''+datetime.datetime.now().strftime("%I:%M%p on %B %d, %Y")
p = user_post(posted_by = posted_by, post_content = post_content, post_id = post_id)
p.save()
return redirect('wall')
else:
if 'username' in request.session:
posts = user_post.objects.all()
return render(request, 'wall/wall_page.html', {'posts': posts})
else:
return redirect('error')
thanks in advance
Upvotes: 0
Views: 1721
Reputation: 410552
request
has a user
attribute that indicates which user made the request (which may be the AnonymousUser
if you don't require logins).
Upvotes: 3