【发布时间】:2017-08-24 06:17:42
【问题描述】:
我有下一个任务,不知道怎么做。
网页向用户显示对象列表。每个对象都有 2 个按钮,其 URL 为 function_detail 和 function_change_history。第一个 url 需要打开关于对象详细信息的页面,第二个 url 需要打开关于更改历史的页面。我使用get_absolute_url 创建第二个网址,但不知道如何创建第一个网址,因为我需要再次使用get_absolute_url。
models.py:
@reversion.register()
class Function(models.Model):
***FIELDS***
def get_absolute_url(self):
return reverse('project:function_change_history', args=[self.project_id, self.code])
urls.py:
url(r'^(?P<project_code>[0-9a-f-]+)/(?P<function_code>[0-9a-f-]+)/change_history/$',
function_change_history,
name='function_change_history'),
url(r'^(?P<project_code>[0-9a-f-]+)/(?P<function_code>[0-9a-f-]+)/detail/$',
function_detail,
name='function_detail'),
可以在get_absolute_url中设置2 url吗?
【问题讨论】:
-
这没有意义。为什么需要它们在 get_absolute_url 中?
-
好吧,我使用
get_absolute_url,因为我需要有关特定对象的信息。 -
这根本不是答案。为什么是这种方法,具体来说?你如何使用它?为什么需要两个结果?
标签: python django python-3.x django-1.10