You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Django REST Framework文档仅显示登录登出URL,其余URL不显示求助

Troubleshooting Missing Views in DRF Documentation

Hey there! Let’s walk through the most common reasons your Register and Location views aren’t showing up in the Django REST Framework (DRF) docs, along with fixes for each:

1. Your Views Aren’t Inheriting DRF Base Classes

DRF’s documentation system only automatically recognizes views that inherit from DRF’s core view classes. If your Register or Location views are using plain Django View instead, they won’t appear in the docs.

Check & Fix:
Ensure your class-based views inherit from APIView, GenericAPIView, or a viewset like ModelViewSet:

from rest_framework.views import APIView
from rest_framework.response import Response

class RegisterView(APIView):
    def post(self, request):
        # Your registration logic here
        return Response({"status": "success"})

2. Function Views Lack the @api_view Decorator

If you’re using function-based views instead of class-based ones, DRF needs the @api_view decorator to identify them as API views for documentation.

Check & Fix:
Add the decorator to your function views and specify allowed HTTP methods:

from rest_framework.decorators import api_view
from rest_framework.response import Response

@api_view(['POST'])
def register_view(request):
    # Your registration logic here
    return Response({"status": "success"})

3. View Permissions Block Anonymous Access

DRF docs default to showing views that anonymous users can access. If your Register/Location views have IsAuthenticated or similar permission classes, they’ll be hidden from unauthenticated visitors.

Check & Fix:

  • Either adjust the permission classes to allow anonymous access (appropriate for views like registration):
    from rest_framework.permissions import AllowAny
    
    class RegisterView(APIView):
        permission_classes = [AllowAny]
        # ... rest of your code
    
  • Or log into the docs page using the provided login view—authenticated users will see views they have permission to access.

4. Routing Configuration Issues

Make sure your views are properly mapped in your URLs, and that their parent routes are included in the scope DRF docs scans.

Check & Fix:
Verify your URL configs:

  • In your main urls.py, confirm you’re including the bouncer.urls correctly:
    from django.urls import path, include
    from rest_framework.documentation import include_docs_urls
    
    urlpatterns = [
        path('docs/', include_docs_urls(title='Your API Docs')),
        path('bouncer/', include('bouncer.urls')),
        path('api-auth/', include('rest_framework.urls')), # For login/logout
    ]
    
  • In bouncer.urls, ensure the views are mapped correctly:
    from django.urls import path
    from .views import RegisterView, LocationView
    
    urlpatterns = [
        path('register/', RegisterView.as_view(), name='register'),
        path('location/', LocationView.as_view(), name='location'),
    ]
    

Also, test the views directly (e.g., visit /bouncer/register/) to confirm they’re working—if the route returns a 404, the docs won’t pick them up either.

5. Custom Schema Class Interference

If you’ve customized DEFAULT_SCHEMA_CLASS in your settings.py, it might prevent DRF from auto-detecting your views.

Check & Fix:
Ensure your REST_FRAMEWORK setting uses a schema class that supports auto-scanning. The default for coreapi-based docs is:

REST_FRAMEWORK = {
    'DEFAULT_SCHEMA_CLASS': 'rest_framework.schemas.coreapi.AutoSchema',
    # Other DRF settings
}

Start with the first two checks—they’re the most common culprits! If none of these work, feel free to share snippets of your view and URL code for deeper debugging.

内容的提问来源于stack exchange,提问作者Melissa Stewart

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.20 09:15:41