safe
필터를 사용하고
을 장고와 내가 <code></code>
태그 만 HTML 태그에 탈출 할, 그 안녕하세요하지만 <code><b>Hello</b></code>
가 <b>Hello</b>
로 렌더링 될 것이다 <b>Hello</b>
렌더링됩니다 의미한다. 그래서 나는 사용자 정의 필터를 쓰기하지만 난이 오류 :사용자 정의 필터 AttributeError
Exception Type: AttributeError
Exception Value:'ResultSet' object has no attribute 'replace'
Exception Location: G:\python\Python\python practice\python website\firstpage\custom_filters\templatetags\custom_filters.py in code_escape, line 10
내 코드는 다음과 같습니다
from bs4 import BeautifulSoup
from django import template
register = template.Library()
@register.filter
def code_escape(value):
soup = BeautifulSoup(value)
response = soup.find_all('code')
string = response.replace('<', '<')
string = string.replace('>', '>')
string = string.replace("'", ''')
string = string.replace('"', '"')
final_string = string.replace('&', '&')
return final_string
template.html
.......
{% load sanitizer %}
{% load custom_filters %}
......
{{ content|escape_html|safe|linebreaks|code_escape }}
.......
"작동하지 않음"이란 의미를 설명 할 수 있습니까? 오류가 발생하면 여기에 넣을 수 있습니까? 몇 가지 샘플 데이터를 제공 할 수 있습니까? 그리고 그 데이터의 출력을 원하십니까? 이 코드 덤프가 정확히 우리가 찾고있는 곳입니까? –
나는 내가 원하는 오류를 추가했다. –