Это home / models.py:
class HomePage(RoutablePageMixin, Page):
template = "home/home_page.html"
components = {'key1': ['alias1', 'ref1'],
'key2': ['alias2', 'ref2'],
'key3': ['alias3', 'ref3'],
'key4': ['alias4', 'ref4'],
'key5': ['alias5', 'ref5']}
def get_comps(self):
comps_list = []
for name in self.components.keys():
alias = self.components.get(name)[0]
current_page_url = request.build_absolute_uri
sub_url_index = current_page_url.find(".")
ref = "http://" + self.components.get(name)[1] + "." + current_page_url[sub_url_index+1:]
the_comp = comp(name, alias, ref)
comps_list.append(the_comp)
return comps_list
class comp(models.Model):
comp_name = ""
comp_alias = ""
comp_ref = ""
def __init__(self, name, alias, ref):
self.comp_name = name
self.comp_alias = alias
self.comp_ref = ref
Wagtail отображает ошибку в строке:
current_page_url = request.build_absolute_uri
Это потому, что не удалось найти объект запроса, который является правильным.
Как я могу получить доступ к объекту запроса в get_comps ()? Я не хочу заменять это на page.get_full_url или любые методы страницы, так как это не дает мне абсолютный URL.