Opened 18 years ago

Closed 18 years ago

Last modified 18 years ago

#2244 closed defect (invalid)

'Hitting returns' in template files are interpreted as NewLines while I want it interpreted as nothing

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

Description

introduction

hi, I am trying to use django's view-template to export some contents to a text files with some format, e.g. carriage return, indentionh etc. But seems every control statement of django templte(if/for/else) are all interpreted as new lines in the exported TXT files, which make my exported files ugly. The followings are my code related:

code

  • views
    !#python
    
        categories = Category.objects.filter(field__in=request.POST.getlist("categories"))
        limits = request.POST.getlist("category_limits")
    
        response = HttpResponse(mimetype="text/csv; charset=utf-16-be")
        response["Content-Disposition"] = "attachment; filename=indesign_export.txt"
        template = loader.get_template("indesign_export.txt")
        context = viewdata(city, categories, limits)
        response.write(unicode(template.render(context), "utf-8").encode("utf-16-be"))
        return response
    
  • templates indesign_export.txt
    <UNICODE-MAC>
    {% for category in categories %}
      {% for subcategory in category.subcategories %}
        {% for listing in subcategory.listings %}
          {% if listing.english_menu_ok %} English menu,                        {% endif %}
          {% if listing.wifi_ok %}         Wi-Fi internet,                      {% endif %}
        {% endfor %}
      {% endfor %}
    {% endfor %}
    
  • Currently what resolution I have is not using Templare.reder(), I mean writing the contents directly to a file, whose content will be outputed as HttpResponse('file_content'). But this violates the MVC priciples, no VIEW, that is templates in django.
  • So I think this is a bug of the template system. Thanks.

Change History (4)

comment:1 by anonymous, 18 years ago

Summary: 'Hitting returns' in template files are interpreted as NewLines while I need it interpreted as plain text'Hitting returns' in template files are interpreted as NewLines while I need it interpreted as nothing

comment:2 by anonymous, 18 years ago

Summary: 'Hitting returns' in template files are interpreted as NewLines while I need it interpreted as nothing'Hitting returns' in template files are interpreted as NewLines while I want it interpreted as nothing

comment:3 by Jacob, 18 years ago

Resolution: invalid
Status: newclosed

This is expected template behavior. Every character you type -- yes, including newlines -- is echoed into the output unless it's a template tag or variable. You might take a look at the spaceless tag, or just be careful about where you put newlines.

comment:4 by Adrian Holovaty, 18 years ago

milestone: Version 0.93

Milestone Version 0.93 deleted

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