Home > Blockchain >  URLs not matching when admin page set to root url in django app
URLs not matching when admin page set to root url in django app

Time:02-06

I building a Django app with drf, the API urls not match correctly when I set admin site at root URL

root url pattern:

urlpatterns = [
path('', admin.site.urls),
path('api/auth/', include("account.urls")),
path('api/main/', include("main.urls")),

]

main URL pattern:

router = routers.DefaultRouter()

router.register('language', LanguageView)


urlpatterns = [
    path('', include(router.urls)),
    
]

when I hit the main API URLs it returns the admin login page, can't fix this yet please help me out.

CodePudding user response:

Well, you have to be logged in to get to admin page. Try to log in and then check if admin site is working correctly.

CodePudding user response:

Include the admin as the last entry in your urls, otherwise your api urls will never match because they are "valid" admin paths and will always be handled by the admin

urlpatterns = [
    path('api/auth/', include("account.urls")),
    path('api/main/', include("main.urls")),
    path('', admin.site.urls),
]
  •  Tags:  
  • Related