反向方法如何构建URL?

时间:2018-07-13 09:16:06

标签: django

我是Django的新手,通过示例书学习Django 这是Post类的get_absolute_url方法

def get_absolute_url(self):
    return reverse('blog:post_detail', args=[self.publish.year, 
        self.publish.strftime('%m'),
        self.publish.strftime('%d'),
        self.slug])

我正在查看源代码reverse

def reverse(viewname, urlconf=None, args=None, kwargs=None, current_app=None):
    if urlconf is None:
        urlconf = get_urlconf()
    resolver = get_resolver(urlconf)
    args = args or []
    kwargs = kwargs or {}

参数部分对我来说很清楚。

def get_urlconf(default=None):
    """
    Return the root URLconf to use for the current thread if it has been
    changed from the default one.
    """
    return getattr(_urlconfs, "value", default)

但是如何解析urlconf?

0 个答案:

没有答案