Coder Social home page Coder Social logo

Comments (2)

hasansezertasan avatar hasansezertasan commented on August 22, 2024

I'm not entirely sure and I didn't think thoroughly but this approach might solve #681.

from sqladmin.

hasansezertasan avatar hasansezertasan commented on August 22, 2024

What I learned so far

Flask Admin Routing

As I said, Flask Admin creates a dedicated blueprint for each view and they are all registered directly to the application.

Consider two views: UserView and PostView. UserView has a blueprint named user_view and PostView has a blueprint named post_view.

Flask Admin also registers an AdminIndexView by default and its blueprint is named admin.

In Flask Admin, every view has an exposed method named index_view.

So the URL-building process is like this:

  • /admin/: url_for("admin.index_view")
  • /admin/user: url_for("user_view.index_view")
  • /admin/user/new: url_for("user_view.create_view")

Flask Admin registers AdminIndexView before all other views. That's why I failed when I tried to adopt its core to use Starlette. AdminIndexView occupies all URLs starting with /admin/* when I use Mount.

Starlette Routing

Mount builds an application (if not provided), and the URL that is used while mounting an application, router, or group of routes is occupied by this application.

Route naming: we can name our routes with a colon separator.

admin_routes = [
  Route(..., name="admin:index_view"),
  Route(..., name="admin:user_view:index_view"),
  Route(..., name="admin:rediscli1:index_view"),
  Route(..., name="admin:rediscli2:index_view"),
]

Conclusion

Each view gets registered (mounted) to the main application. Not to an application to be mounted to the main application.

Each view has a dedicated blueprint (Router or Mount instance) and each exposed function gets registered to this blueprint.

Questions

  • Do we need something like AdminIndexView?
  • Do we need a separate application instance to mount admin to the main application?
  • We can name expose functions like rediscli:index_view and they'll be directly registered to the SQLAdmin application and will be accessible by doing url_for("admin:rediscli:index_view") but what about the URLs?
  • How does moving list, details, delete, create, edit, export, and ajax_lookup methods to the views as exposed methods sound like? This is the Flask Admin approach to the problem.

In the end problem remains: View can not have a name prefix... So if the user has two custom views with the same exposed URLs, there will be conflicts...

from sqladmin.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.