Search code examples
djangodjango-templatesdjango-admin

Does Django admin support regex url?


I writed something like this: url(r'^oog\d{3}/', admin.site.urls) But when I open admin site, then visit some model. It show me the url is 0.0.0.0:8000/oog000/app... and it could not open.

Does re_path support admin.site.urls?

Thanks.


Solution

  • I don't think this is possible without diving deep into the AdminSite object.. and I don't see any real benifit of being able to access the same admin page with oog001 and oog002

    I was able to get it to at least run with:

    re_path(r'^admin(([0-9]+)/)?', admin_site.urls),
    

    But immediately:

    http://127.0.0.1:8000/admin12/
    
    admin.index() takes from 2 to 3 positional arguments but 4 were given
    

    args looks like:

    (<WSGIRequest: GET '/admin12/'>, '12/', '12')
    

    You can pop off those two 12's and get the index to load, but than any other url in the admin ends up like

    http://127.0.0.1:8000/adminapp1/
    

    None of the Model tables work, I presume you've also got to pop the numbers off:

    http://127.0.0.1:8000/adminapp1/model1/
    
    ModelAdmin.changelist_view() takes from 2 to 3 positional arguments but 4 were given
    

    I'd suggest not doing this