django-rest-frameworkdjango-swagger

Swagger navigation like https://petstore.swagger.io/#/pet doesn't work in my projects


All the Swagger apps I've seen have navigation between endpoints-related blocks like this: https://petstore.swagger.io/#/store/getInventory

When you click on certain blocks the URL changes. Can't understand what I'm doing wrong, but I have nothing like this. My browser shows the same URL all the time, i.e. it's like 'https://petstore.swagger.io/' without #, etc.

Some example of how I'm using Swagger. To make sure it's not about my project, tried with a tutorial one, but it has the same problem

serializers.py:

class PostSerializer(serializers.HyperlinkedModelSerializer):
    class Meta:
        model = Post
        fields = ('author', 'title')

views.py:

class PostViewSet(viewsets.ModelViewSet):
    queryset = Post.objects.all()
    serializer_class = PostSerializer

urls.py:

router = DefaultRouter()
router.register('posts', views.PostViewSet)

schema_view = get_swagger_view(title='Posts API')

urlpatterns = [
    url('^$', schema_view),
    url(r'^', include(router.urls)),
    url(r'^api-auth/', include('rest_framework.urls', namespace='rest_framework'))
]

What I'm doing wrong? Thanks!!


Solution

  • Enable deeplinking in your swagger ui config file:

    deepLinking: true
    

    https://github.com/swagger-api/swagger-ui/blob/8dab91f184103be794ae2fcfeb67b02126730e88/docs/deep-linking.md