-1
일부 읽기 전용 속성을 가진 제 3 자 코드를 사용하고 있습니다. 분명히 관계없이 변경하고 싶습니다.파이썬 해킹 읽기 전용 속성
나는 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
왜 처음에 델을 해보려고합니까? 왜 page.url을 직접 할당하지 않습니까? –
이 'AttributeError : 속성을 설정할 수 없습니다'라는 메시지가 나타납니다. – Lee
'page' 클래스의 코드를 표시해야합니다. –