채팅에 많은 사용자를 반환하는 맞춤 템플릿 태그를 작성했습니다.django 템플릿 태그의 변수 값
{% chat_online chat_channel %}
그러나 토큰 대신 그 변수의 값으로서 chat_channel
값을 수신하는 것처럼 보인다.
무엇이 문제입니까?
채팅에 많은 사용자를 반환하는 맞춤 템플릿 태그를 작성했습니다.django 템플릿 태그의 변수 값
{% chat_online chat_channel %}
그러나 토큰 대신 그 변수의 값으로서 chat_channel
값을 수신하는 것처럼 보인다.
무엇이 문제입니까?
HTML의 템플릿 태그 정의 ({% ... %}
)는 django의 템플릿 엔진에서 구문 분석되는 텍스트이므로, tell django to actually lookup the variable in the context being rendered with the name chat_channel
이 필요합니다.
class FormatTimeNode(template.Node):
def __init__(self, date_to_be_formatted, format_string):
self.date_to_be_formatted = template.Variable(date_to_be_formatted)
...
def render(self, context):
try:
actual_date = self.date_to_be_formatted.resolve(context)
...
except template.VariableDoesNotExist:
return ''
template.Variable(date_to_be_formatted)
은 (예에서 blog_entry.date_updated
) 템플릿 태그에 전달 된 원시 값에서 템플릿 변수를 생성하고 self.date_to_be_formatted.resolve(context)
은에서 그 변수의 실제 값을 찾는 : 워드 프로세서에서이 예는 매우 분명하다 템플릿을 컨텍스트와 비교하여 해결합니다.
코드를 표시하지 않으면 커스텀 태그의 문제점을 어떻게 알려줄 수 있습니까? –