Skip to content

Bug: CustomViews do not render when added to Admin after mounting to App #731

Description

@JoeNaso

Describe the bug
CustomViews do not load when added to admin instance after mounting

To Reproduce
Create an Admin instance, add the custom view, then mount the Admin to an app. This will render fine.

However, the following will not render the custom view:

  1. Create admin instance
  2. Mount admin to app
  3. Add custom view

The first scenario will render the specified templates just fine, while the 2nd returns 404. This is confusing because ModelViews are not affected in the same way

Environment (please complete the following information):

  • Starlette-Admin version: ">=0.15.1"
  • ORM/ODMs: SQLAlchemy

Additional context
App being mounted is a FastAPI instance

# This works as expected and the custom view is accessible at the path
def register_admin(app: FastAPI) -> FastAPI:
    admin = Admin(
        ...,
        templates_dir="templates/admin/",
        index_view=admin_home.HomeView(label="Home", icon="fa fa-home"),
    )

    # Custom Views
    admin.add_view(
        embeds.DashboardsView(
            label="Dashboards",
            icon="fa fa-gauge",
            path="/dashboards",
            template_path="dashboards.html",
            add_to_menu=True,
        )
    )

    admin.mount_to(app)
    return app

# This returns a 404 when accessing the customView path
def register_admin(app: FastAPI) -> FastAPI:
    admin = Admin(
        ...,
        templates_dir="templates/admin/",
        index_view=admin_home.HomeView(label="Home", icon="fa fa-home"),
    )
     
   admin.mount_to(app)

    # Custom Views
    admin.add_view(
        embeds.DashboardsView(
            label="Dashboards",
            icon="fa fa-gauge",
            path="/dashboards",
            template_path="dashboards.html",
            add_to_menu=True,
        )
    )


    return app

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions