开发者

How to assemble a link to a specific view in django admin?

开发者 https://www.devze.com 2023-04-02 11:59 出处:网络
Inside my subclass of admin.ModelAdmin, I want to manually assemble a url to a different edit view for a different model.

Inside my subclass of admin.ModelAdmin, I want to manually assemble a url to a different edit view for a different model.

What I currently have is:

开发者_开发问答
  • app
  • model
  • id (PK of the model)

The question now is how I can obtain the prefix of the server. e.g. I access the admin via url http://myserver.com/admin/app/model/ How can I retrieve http://myserver.com/admin in a server agnostic way inside my ModelAdmin subclass ?


Use the reverse function, as documented in reversing admin urls.

For example:

urlresolvers.reverse('admin:appname_modelname_change', args=(id,))
0

精彩评论

暂无评论...
验证码 换一张
取 消