템플릿에서 텍스트를 들여 쓰는 데 문제가 있습니다.  
mainTemplate.html에서 다중 을 사용하여 텍스트의 시작 부분을 들여 쓰지만 텍스트가 새 줄로 계속되면 새 줄이 들여 쓰기되지 않습니다. 그래서 필터를 사용하여 각 줄을 올바르게 들여 쓰려고했습니다. 내 템플릿은 {% include %}
태그를 사용 하여 들여 쓰려는 텍스트의 하위 템플릿 (display_citations.html)을 렌더링하고 포함합니다. 렌더링 된 서브 템플릿을 'indent'필터에 전달할 수 있도록 문자열로 저장할 수 있습니까? 그렇지 않은 경우 해당 하위 템플릿의 내용을 들여 쓰는 다른 방법이 있습니까?
mainTemplate.html
{% for publication in value %}
{% include "software/display_citations.html" with publication=publication url="/select_citations/"%}
{% endfor %}
display_citations.html
{{ publication.authors }}. {{ publication.title }}{% if not publication.title_ends_with_punct %}.{% endif %}{% if publication.journal %} {{ publication.journal }}.{% endif %}{% if publication.month %} {{ publication.month_long }}{% endif %} {{ publication.year }}.{% if publication.volume %}{% if publication.number %} {{ publication.volume }}({{ publication.number }}){% else %} {{publication.volume}}{% endif %}{% endif %}{% if publication.pages %}: {{ publication.pages }}.{% else %}.{% endif %}
<br><a href="{{url}}{{ publication.pk }}/?ris" target="_blank" download="Citations.ris">RIS</a>
views.py
register = template.Library()
@register.filter(name='indent')
@stringfilter
def indent(value, arg=1):
import re
regex = re.compile("^", re.M)
return re.sub(regex, "\t"*int(arg), value)
mainTemplate.html에서해야 할 일은 어떻게 든 내 하위 템플릿에서 문자열을 만든 다음 내 필터에 전달하는 것입니다 ...? 아마도 다음과 같습니다.
text_to_be_indented = {% include "software/display_citations.html" with publication=publication url="/select_citations/"%}
{{ text_to_be_indented | indent:"4" }}
너무 많이 사용해야
하나요? div
스타일로 시도해 보지 않겠 margin-left:20px;
습니까?
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다