-1
いくつかの読み取り専用プロパティーを持つサードパーティーのコードを使用しています。 私は明らかに関係なくそれらを変更したいと思います。Pythonがハッキングする読み取り専用プロパティー
私はdel
を使用してみましたが、私は入れません:AttributeError: can't delete attribute
をここでは私のコードです:
for page in suggested_pages:
url = page.url + '?source=smart_404'
full_url = page.full_url + '?source=smart_404'
del page.url
del page.full_url
page.url = url
page.full_url = full_url
編集人々はプロパティのコード
@property
def full_url(self):
"""Return the full URL (including protocol/domain) to this page, or None if it is not routable"""
url_parts = self.get_url_parts()
if url_parts is None:
# page is not routable
return
site_id, root_url, page_path = url_parts
return root_url + page_path
@property
def url(self):
"""
Return the 'most appropriate' URL for referring to this page from the pages we serve,
within the Wagtail backend and actual website templates;
this is the local URL (starting with '/') if we're only running a single site
(i.e. we know that whatever the current page is being served from, this link will be on the
same domain), and the full URL (with domain) if not.
Return None if the page is not routable.
"""
url_parts = self.get_url_parts()
if url_parts is None:
# page is not routable
return
site_id, root_url, page_path = url_parts
if len(Site.get_site_root_paths()) == 1:
# we're only running a single site, so a local URL is sufficient
return page_path
else:
return root_url + page_path
を求めてきましたコードはWagtail CMS
から来ました210
なぜあなたは最初にそれらをdelしようとしますか?単にpage.urlを直接割り当てるのはなぜですか? –
この 'AttributeError:属性を設定できません'を取得しました – Lee
'page'クラスのコードを表示する必要があります。 –