引用模板中的数据浏览 URL
I'd like to integrate django Databrowse into my application.
It comes down to pointing to databrowse urls from within template or view for enhanced drill down functionality of the databrowse.
Is there an easy way to extract the url from a databrowse object?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
好吧,一种简单的方法是构造您想要的 url,并将其传递到模板中:
然后在模板中(假设您的 databrowse 位于
/databrowse
:这将为您提供一个 url例如:
/databrowse/app_name/model_name/objects/1
。Well, one easy way would be to just construct the url you want, and pass it into the template:
And then in the template (assuming you have databrowse situated at
/databrowse
:Which would give you a url like:
/databrowse/app_name/model_name/objects/1
.您可以按照 中显示的格式重新创建数据浏览 URL databrowse urls.py
您也许可以获得 url标记 通过传递视图名称+参数来在模板中工作。
但是,如果您浏览源,它看起来 databrowse 会向它使用的对象添加一个“url”属性。
编辑:
给定一个 EasyModel 实例,您可以执行以下操作:
大多数“Easy”类都有 url() 或 urls() 方法。
You could recreate the databrowse urls in the format thats show in the databrowse urls.py
You might be able to get the url tag to work in your template by passing the view name + arguments.
However, if you browse the source, it looks like databrowse will add a 'url' attribute to the objects it works with.
EDIT:
Given an EasyModel instance, you can do the following:
Most of the 'Easy' classes have a url() or urls() method on them.
最终编写了 mixin 类来获取相关的 EasyInstance 并重用它的 url() :
现在在我的模板中,我可以重用指向数据浏览对象 url 的
my_model_instance.url
标签。Ended up writing mixin class that fetches relevant EasyInstance and reuses the
url()
of it:Now in my templates I can reuse
my_model_instance.url
tag pointing to databrowse object url.