Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Facing runtime error #135

Open
sodrooome opened this issue Mar 17, 2019 · 1 comment
Open

Facing runtime error #135

sodrooome opened this issue Mar 17, 2019 · 1 comment

Comments

@sodrooome
Copy link

I was wondering if I could get your help on this, so i would like to create a single nested simple router but unfortunately, it's result the error like RuntimeError: parent registered resource not found.

here's my urls.py which contains the following code like this:

router = routers.DefaultRouter()
router.register(r'accounts', AccountViewSet) 
router.register(r'projects', ProjectViewSet)

accounts_router = routers.NestedSimpleRouter(router, r'accounts', lookup='account')
accounts_router.register(r'projects', AccountProjectsViewSet)

I can't seem to figure out why this error is still occurring, any help would be much appreciated

@moonburnt
Copy link

moonburnt commented Nov 29, 2022

going to add to this topic, as it seems related - at this moment, it seems like NestedDefaultRouter is not working properly too.
Or maybe missing its whole "DefaultRouter" purpose.

Doing things the following way gives me the very same RuntimeError OP has got:

from rest_framework_nested import routers

router = routers.DefaultRouter()

category_router = routers.NestedDefaultRouter(
    parent_router=router,
    parent_prefix="category",
)

Doing things the following way kinda work:

from rest_framework_nested import routers

from views import TestViewSet, Foo, Bar

router = routers.DefaultRouter()

router.register(
    prefix="test",
    viewset=TestViewSet,
)

category_router = routers.NestedDefaultRouter(
    parent_router=router,
    parent_prefix="test",
)

category_router.register(
    prefix="foo",
    viewset=Foo,
)
category_router.register(
    prefix="bar",
    viewset=Bar,
)

I mean - router itself now works, I'm able to get to /test/ endpoint.
However, it does not work as a default router.

What I've expected:

  • Entering /test/ gives me the same layout as DefaultRouter usually does, just for
    endpoints registered to category_router. E.g /test/foo/ and /test/bar/.

What I've got:

  • Entering /test/ renders the TestViewSet. I'm able to access /test/foo/ and /test/bar/,
    but miss the APIRootView

Am I doing it wrong, or? How do I correctly get a DefaultRouter-like behavior (router that renders a list of endpoints attached to it on its base endpoint) on a nested router?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants