0

It is the code of my Room model

class Room(models.Model):
    #host
    #topic
    name=models.CharField(max_length=200)
    desccription=models.TextField(null=True, blank=True)
    #participants=
    updated=models.DateTimeField(auto_now=True)
    created=models.DateTimeField(auto_now_add=True)

and here in views.py , I'm trying to get id

def room(request, pk):
    room=Room.objects.get(id=pk)
    context={'room':room}
    return render(request, 'base/room.html', context)

but it shows error

AttributeError at /room/1/
'Room' object has no attribute 'get'
Request Method: GET
Request URL:    http://127.0.0.1:8000/room/1/
Django Version: 4.0.4
Exception Type: AttributeError
Exception Value:    
'Room' object has no attribute 'get'
1
  • Show us the full stack trace for the error please. Commented Apr 27, 2022 at 4:04

1 Answer 1

1

That error can occur when models and views have similar names and there is a case error in urls.py. Check that you haven't used 'Room' with a capital 'R' in urls.py when you want to use 'room' with a lowercase 'r', eg you've used something like

path('', views.Room, name='room')

which should be

path('', views.room, name='room')
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.