Code

Opened 7 years ago

Closed 7 years ago

#3839 closed (invalid)

carriage returns in template system translate to spaces in output

Reported by: milesvp@… Owned by: adrian
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: UI/UX:

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.

Attachments (0)

Change History (1)

comment:1 Changed 7 years ago by SmileyChris

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Resolution set to invalid
  • Status changed from new to closed

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.

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.