In my django app, i need to check if a user exists using a phone number. The login is done using phone number and OTP. I can check if the user exists by a get request to
"/api/profiles/<primary key here>/".
However if I request
"/api/profiles/"
i get a list of all the users in the database.
I need my app to return nothing if requesting
"/api/profiles/"
and user details if requesting
"/api/profiles/<primary key here>/"
How do I do this?
The serializer is a basic model serializer
class UserProfileSerializer(serializers.ModelSerializer):
class Meta:
model = UserProfile
fields = [
"id",
"is_superuser",
"fullname",
"email",
"is_staff",
"is_active",
# "birthdate",
"phone_number",
"created_at",
"updated_at",
]
Urls:
router = routers.DefaultRouter()
router.register(r"profiles", views.UserProfileViewSet)
urlpatterns = [
path("admin", admin.site.urls),
path("restauth/", include("rest_framework.urls", namespace="restauth")),
path("api/", include(router.urls)),
views:
class UserProfileViewSet(viewsets.ModelViewSet):
queryset = UserProfile.objects.all()
serializer_class = UserProfileSerializer
Can you try this code