为什么我需要to_url(self, value)Django 中的路径转换器中的方法?
我在官方文档上只能找到几个例子,无法理解这个方法的用法。
to_url() 到底做了什么?
class FourDigitYearConverter:
regex = '[0-9]{4}'
def to_python(self, value):
return int(value)
def to_url(self, value):
return '%04d' % value
Run Code Online (Sandbox Code Playgroud)