Skip to content

fix: CustomView added after mount_to is now accessible (#731) - #766

Open
SHYXIN wants to merge 1 commit into
jowilf:mainfrom
SHYXIN:fix/custom-view-after-mount
Open

fix: CustomView added after mount_to is now accessible (#731)#766
SHYXIN wants to merge 1 commit into
jowilf:mainfrom
SHYXIN:fix/custom-view-after-mount

Conversation

@SHYXIN

@SHYXIN SHYXIN commented May 17, 2026

Copy link
Copy Markdown
Contributor

Summary

When CustomView was added via add_view() after mount_to() had already been called, the route was inserted into self.routes but not into the already-created Starlette sub-application, causing 404 errors.

ModelViews were not affected because their routes are registered during init_routes() before mount_to() is called.

Changes

  • starlette_admin/base.py:102 — Added self._mounted_app = None in __init__
  • starlette_admin/base.py:573 — Save reference to created admin_app in mount_to()
  • starlette_admin/base.py:274-283 — In setup_view(), if mounted, also add route to mounted app's router via add_route()
  • tests/test_views.py — Added test_custom_view_after_mount test

Testing

  • New test test_custom_view_after_mount passes
  • All 15 views tests pass

When CustomView was added via add_view() after mount_to() had already
been called, the route was inserted into self.routes but not into the
already-created Starlette sub-application, causing 404 errors.

Changes:
- BaseAdmin.__init__: add self._mounted_app = None
- BaseAdmin.mount_to: save reference to created admin_app
- BaseAdmin.setup_view: if mounted, also add route to mounted app's 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

Successfully merging this pull request may close these issues.

1 participant