I have the following urls in my Django application:
path('rooms/<room_id>',views.home,name='home'),
models:
class ChatRoom(models.Model):
eid = models.CharField(max_length=64, unique=True)
name = models.CharField(max_length=25)
views
def rooms(request):
room = UserProfile.objects.filter(user=request.user).values()[0]['room_id']
rooms = ChatRoom.objects.all().values()
user = User.objects.filter(username=request.user)
return render(request,'chat/rooms.html',{'rooms':rooms,'room_user':room})
Here <room_id> is variable i.e it depends on the eid of a Room model. A user can be a part of only one room. Therefore, the user can access only one <room_id>, let us say '4'. So, a user can access only rooms/4/. How can I restrict the user from entering into other URLs e.g. /rooms/5/ ?.