在路径转换器中使用url()方法需要什么?Djang公司

2024-04-25 17:18:07 发布

您现在位置:Python中文网/ 问答频道 /正文

在Django中,我需要path converter中的to_url(self, value)方法做什么?你知道吗

我在公文上只能找到几个例子,不明白这种方法的用法。你知道吗

tou url()到底做什么?你知道吗

class FourDigitYearConverter:

    regex = '[0-9]{4}'

    def to_python(self, value):
        return int(value)

    def to_url(self, value):
        return '%04d' % value

Tags: topathdjango方法selfurl用法return