Django Module Object is Not Callable Problem

54 Views Asked by At

I'm struggling to fix an error that doesn't allow me to access my /api/lead/ URL, as I keep getting an error "module object is not callable. Within my DjangoApp project, I have one other folder named api, and one other folder with the standard name of the project, which in my case is "DjangoApp".


api/models.py :

from django.db import models

# Create your models here.

class Lead(models.Model):
    name = models.CharField(max_length=100)
    email = models.EmailField()
    message = models.CharField(max_length=300)
    created_at = models.DateTimeField(auto_now_add=True)


api/LeadListCreate.py :


from .models import Lead
from api import LeadSerializer
from rest_framework import generics


class LeadListCreate(generics.ListCreateAPIView):
    queryset = Lead.objects.all()
    serializer_class = LeadSerializer


api/LeadSerializer.py :

from rest_framework import serializers
from .models import Lead

class LeadSerializer(serializers.ModelSerializer):
    class Meta:
        model = Lead
        fields = ('id', 'name', 'email', 'message')

api/urls.py :

from django.urls import path
from . import views

urlpatterns = [
    path('api/lead/', views.LeadListCreate.as_view() ),
]



DjangoApp/urls.py :

from django.contrib import admin
from django.urls import path, include


urlpatterns = [
    path('admin/', admin.site.urls),
    path('', include('api.urls')),
    
]
1

There are 1 best solutions below

0
IvesCosta On

the error is very generic, and several things could be happening, I recommend running your application in debug mode and doing it step by step until you find where it is breaking. vscode and pycharm have this tool