'AgencyRegistration' object has no attribute 'get'

I'm trying to create an endpoint using Django REST framework, but when I'm trying to get the data from the endpoint I'm getting the following error: AttributeError: 'AgencyRegistration' object has no attribute 'get'. Here's my code

models.py

`class AgencyRegistration(models.Model):
    agency_name = models.CharField(max_length=200)
    tax_id_number = models.IntegerField(max_length=12)
    address_street = models.CharField(max_length=220)
    city = models.CharField(max_length=50)
    county = models.CharField(max_length=50)
    state = models.CharField(max_length=100)
    zip_code = models.CharField(max_length=50)
    first_name = models.CharField(max_length=50)
    last_name = models.CharField(max_length=50)
    title = models.CharField(max_length=200)
    email = models.CharField(max_length=200)
    phone = models.CharField(max_length=50)
    children_amount = models.CharField(max_length=100)
    age_range = models.CharField(max_length=100)
    program_benefit = models.CharField(max_length=200)
    organization_type = models.CharField(max_length=200)
    how_did_you_hear = models.CharField(max_length=200)

    def __str__(self):
        return self.agency_name`

views.py

`def agency_registration(request):
    agency_data = AgencyRegistration.objects.all()
    serializer = AgencyRegistrationSerializer(agency_data, many=True)
    return render(JsonResponse(serializer.data, safe=False))`

serializers.py

`class AgencyRegistrationSerializer(serializers.ModelSerializer):
    class Meta:
        model = AgencyRegistration
        fields = [
            'id', 
            'agency_name', 
            'tax_id_number', 
            'address_street', 
            'city',
            'county',
            'state',
            'zip_code',
            'first_name',
            'last_name',
            'title',
            'email',
            'phone',
            'children_amount',
            'age_range',
            'program_benefit',
            'organization_type',
            'how_did_you_hear'
        ]`

urls.py

`urlpatterns = [
    path('agency-registration/', views.AgencyRegistration),
]`

You cannot use Model as a path in urlpatterns. You can put there only views, like your agency_registration. It should be:

urlpatterns = [
    path('agency-registration/', views.agency_registration),
]
Back to Top