如何在Web请求上下文之外(即在Model属性getter中)生成完全限定的URL(包括协议和端口)?
例如,我有一个模型如下:
class Package(models.Model):
name = models.CharField(max_length=200)
description = models.CharField(max_length=500)
version = models.CharField(max_length=30)
pub_date = models.DateTimeField('date published')
filename = models.CharField(max_length=200)
is_published = models.BooleanField()
release_notes_url = models.CharField(max_length=1000)
platform = models.ForeignKey(Platform)
groups = models.ManyToManyField(Group)
@property
def package_url(self):
return <<some root url>> + "/foo/" + self.filename
从package_url
我想获得完整的合格网址。