Opened 18 years ago

Closed 18 years ago

#3839 closed (invalid)

carriage returns in template system translate to spaces in output

Reported by: milesvp@… Owned by: Adrian Holovaty
Component: Template system Version: 0.96
Severity: Keywords: carriage_returns
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

Following the templating chapter in http://www.djangobook.com/en/beta/chapter04/. I noticed that my carriage returns were translating to spaces in my output html.

#####views.py#####################################
from django.shortcuts import render_to_response

def test(request):
    return render_to_response('test.html')
##################################################

#####test.html####################################
<html><body>This is a te
st</body></html>
##################################################

#####rendered output##############################
This is a te st
##################################################

The real problem comes when I want to do something like this

##################################################
{% extends 'base.html' %}

{% block content %}
<p>In {{ hour_offset }} hour 
{%ifnotequal hour_offset 1%}
s
{%endnotequal%}
, it will be {{ next_time }}.</p>
{% endblock %}
###################################################

######rendered output for offset=2, minus extended code##
In 2 hour s , it will be 2007-03-27 13:47:20.009487.
#########################################################

Note the spaces around the s. This may be a design decision, but it feels very wrong. Python wants whitespace.

Change History (1)

comment:1 by Chris Beaven, 18 years ago

Resolution: invalid
Status: newclosed

Python wants whitespace.

But you're not in python, you're in HTML. HTML handles line breaks as white spaces.

I suggest you write a template tag to strip all line breaks.

Note: See TracTickets for help on using tickets.
Back to Top