开发者

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

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜