0

I have the django model called "create-chat" and there I write names of people I want to see in a group chat. So. I created the model, but I don't know how to make a condition whether user is in django_db or no, if so then I want to show them the button "join chat" And after clicking the button he will be transferred to the url sitename.com/lobby/1 Now I have the view that shows the page /lobby/any_number First of all I'd to block these pages from users and only if the user is in django_db He is able to visit the page Lobby/1 ONLY THE lobby/1 not lobby/2 I don't ask you to do it, I just want you to explain me how to do it, or maybe advice me some articles about my problem. https://i.stack.imgur.com/FQw4Y.jpg

..1). How to block all users for visiting this url sitename.com/1234 <- here goes any number u d liked. ( 4 characters ) So now I blocked all the users for visiting this page, and how now make it visible for a certain users/user?

1 Answers1

0

I am assuming you are storing the information in User object.

usr = User.objects.get(username = whateveristheusername)

if usr is not None:

#User Exist. Click to join chat

else:

#Create User or any other viable functionality

Community
  • 1
  • 1
Jeevan Bodas
  • 148
  • 5
  • 13
  • I will draw my db and what I want from you. To make sure you understand me. Wait a min. –  Dec 01 '17 at 10:10
  • I need to make a condition ( if logged in user, if his username is in chat model then he will receive the button –  Dec 01 '17 at 10:32
  • And how to block all users from lobby/any_number page, I want to show the page only for users which usernames are in the db can be redirected to lobby/1 after clicking the button –  Dec 01 '17 at 10:34
  • You have to put the condition in template like {% if userAvail %} #do_something. You need to pass this userAvail value from your views.py to template using context. Additionally, you can also make use of request.session – Jeevan Bodas Dec 01 '17 at 11:37
  • Okay, I will try it. –  Dec 01 '17 at 12:21