Code Monkey home page Code Monkey logo

python-docx-template's Introduction

python-docx-template

Use a docx as a jinja2 template

Introduction

This package uses 2 major packages :

  • python-docx for reading, writing and creating sub documents
  • jinja2 for managing tags inserted into the template docx

python-docx-template has been created because python-docx is powerful for creating documents but not for modifying them.

The idea is to begin to create an example of the document you want to generate with microsoft word, it can be as complex as you want : pictures, index tables, footer, header, variables, anything you can do with word. Then, as you are still editing the document with microsoft word, you insert jinja2-like tags directly in the document. You save the document as a .docx file (xml format) : it will be your .docx template file.

Now you can use python-docx-template to generate as many word documents you want from this .docx template and context variables you will associate.

Documentation

Please, read the doc

Other projects

If you like python-docx-template, please have a look at some of my other projects :

python-docx-template's People

Contributors

alanoe avatar arthaslixin avatar chaberch avatar dralexxx avatar dreizehnutters avatar edwinsmulders avatar elapouya avatar giancab25 avatar hugokernel avatar idrisnacer avatar jfcorbett avatar jfdesrochers avatar jhpyle avatar karolzlot avatar komawar avatar krysros avatar lcrs123 avatar majkls23 avatar mx2048 avatar mzetea avatar nostalgiaz avatar rgusmero avatar robert-malai avatar sailingnn avatar slarag avatar staffanm avatar teut2711 avatar timgates42 avatar vesatoivonen avatar wafi543 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

python-docx-template's Issues

issue with Linux

Hi,

I was able to run create the word doc successfully in windows, but it doesn't seem to render with the linux distribution I'm using (Scientific Linux 6.6). Am I setting something wrong or is there a workaround.

Joeny

Use with Django Template instead of Jinja2

Hey! I'm planning to use the package to render some Docx on a project but I would like to use Django tags instead of Jinja2. I think that to do it I'll need to replace an import on your library: instead of from jinja2 import Template -> from django.template import Template. And then pass the context as a django.template Context object. Is that thing possible and compatible with the project License?

Thank you.

Dynamically Add Section

Not sure this is best asked here so I apologize if not.

Lets say my word document has:

Title:

Notes:

Links:

and I am pulling a list of these from a database. I have the all writing out to a text file just fine in a loop just not sure using the word document template now to get it to create a new page for each set that gets pulled out. Right now it goes though the database and just overwrites the jinja2 variables until it gets the the last one then saves the doc. So it is pulling the data and putting it into the document, but I need to have it create a new page for each one.

docxtpl 1.7 demo is not working on python 2.7

Hello. I just downloaded this library (version 1.7), and the basic demo (under Quickstart-usage) doesn't appear to be working:

from docxtpl import DocxTemplate
doc = DocxTemplate("template2.docx")
context = { 'Date':'September 20, 2015','AddresseeFirst':'John','AddresseeLast':'Doe'}
doc.render(context)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/. . ./venv/lib/python2.7/site-packages/docxtpl/__init__.py", line 79, in render
    xml = self.build_xml(context)
  File "/Users/ . . . /venv/lib/python2.7/site-packages/docxtpl/__init__.py", line 68, in build_xml
    xml = self.get_xml()
  File "/Users/ . . . /venv/lib/python2.7/site-packages/docxtpl/__init__.py", line 29, in get_xml
    return etree.tostring(self.docx._element.body, encoding='unicode', pretty_print=True)
AttributeError: 'Document' object has no attribute '_element'

I'm running this on a venv running python 2.7.5, python-docx version 7.4 and jinja2 version 2.7.3.

Any advice would be much appreciated. This looks like just the project I've been hoping to find.

Rowspan for tables?

Hello! Thanks to the conributers for a helpfull lib.

Is it possible to declare a rowspan in a dynamic table? Colspan works just fine so I assumed the rowspan tag should exist too but it seems it doesn't.
Did a brief search of the source code. Found only the colspan function.

Sub Doc error: TypeError: unsupported operand type(s) for -: 'Undefined' and 'Undefined'

Hi,
Thank you so much for this great app!
I'm attempting to insert a sub doc into a doc, using the code from subdoc.py and the sample docs.
I am able to create the sub doc, and when I print it out to the console, I see that my variables have been assigned correctly.

However, when I assign the sub doc to the context and attempt to render I get the following traceback:

  File "C:\Users\user\Dropbox\virtualenvs\wakeup27\wakeup\forms\models.py", line
 112, in generateFile
    doc.render(context)
  File "C:\Users\user\Dropbox\virtualenvs\wakeup27\lib\site-packages\docxtpl\__init__.py", line 115, in render
    xml = self.build_xml(context,jinja_env)
  File "C:\Users\user\Dropbox\virtualenvs\wakeup27\lib\site-packages\docxtpl\__init__.py", line 80, in build_xml
    xml = self.render_xml(xml, context, jinja_env)
  File "C:\Users\user\Dropbox\virtualenvs\wakeup27\lib\site-packages\docxtpl\__init__.py", line 73, in render_xml
    dst_xml = template.render(context)
  File "C:\Users\user\Dropbox\virtualenvs\wakeup27\lib\site-packages\jinja2\environment.py", line 989, in render
    return self.environment.handle_exception(exc_info, True)
  File "C:\Users\user\Dropbox\virtualenvs\wakeup27\lib\site-packages\jinja2\environment.py", line 754, in handle_exception
    reraise(exc_type, exc_value, tb)
  File "<template>", line 1, in top-level template code
TypeError: unsupported operand type(s) for -: 'Undefined' and 'Undefined'

Do you have any idea how I can fix this?

sub-document (python-docx features not supported - Tables and Default Styles)

Thanks for writing this module very handy.

I am comparing features of building document content via (A) new python-docx document, and (B) python-docx-template subdocument. The hope is the two will produce equivalent content, although the following differences are noted below. Are these known limitations?

  1. B does not render any tables, where A does. This is problematic as I need more control over table creation (i.e. merge, style per row and cell, etc.).
  2. B throws exception raise KeyError("no style with name '%s'" % key) on setting default style, i.e. paragraph.style = 'List Bullet'

code snip below:

def addDocContent(doc):
"Adds content to a python-docx object"
recordset = [
            {'qty' : 1, 'id' : 101, 'desc' : "Spam"},
            {'qty' : 2, 'id' : 42, 'desc' : "Eggs"},
            {'qty' : 3, 'id' : 631, 'desc' : "Spam,spam,eggs,and spam"},
            ]

doc.add_heading('Document Title', 0)

p = doc.add_paragraph('A plain paragraph having some ')
p.add_run('bold').bold = True
p.add_run(' and some ')
p.add_run('italic.').italic = True

h = doc.add_heading('Heading, level 1', level=1)
#h.style = 'Intense Quote'
#doc.add_paragraph('Intense quote', style='IntenseQuote')

p = doc.add_paragraph(
    'first item in unordered list'#, style='ListBullet'
)
#p.style = 'List Bullet'

p = doc.add_paragraph(
    'first item in ordered list'#, style='ListParagraph'
)
#p.style = 'List Paragraph'

doc.add_picture('monty-truth.png', width=Inches(1.25))

#python-docx-template subdoc will not render this table
table = doc.add_table(rows=1, cols=3)
hdr_cells = table.rows[0].cells
hdr_cells[0].text = 'Qty'
hdr_cells[1].text = 'Id'
hdr_cells[2].text = 'Desc'
for item in recordset:
    row_cells = table.add_row().cells
    row_cells[0].text = str(item['qty'])
    row_cells[1].text = str(item['id'])
    row_cells[2].text = item['desc']

doc.add_page_break()

Support HTML tags using template variables

Hi @elapouya ,
Very good library, thanks for the good work here.

Would it be possible that we can use template variables which contains the html tags (the text content comes from a HTML editor)?

We don't need the complex styles with external css classes. we only wanna keep the following:


  • new line
    • Bold/italic text

    Any advise?

    Thanks in advance.:)

Jinja2 custom filters

Is there any way to use custom filters whithin templates?
Passing functions within context works, but maybe I'm missing something?

Nested Templates?

Is it possible for you to implement functionality to do nested templates, maybe with subdocs?

Basically, I want to have a main template with several jinja tags. Then I would like to define tables in a few other template files, each containing jinja tags. Finally, I would like to pull records from a database, and then loop through them, creating a table in the main doc for each record, based on a table template. I can do this with the existing code base, but I have to build the tables in my script as opposed to defining them in a Word template. I hope that makes sense.

[User Help] replace a picture?

I have a docx, I can modify all texts elements with python-docx-template but there's a also a picture in the docx header.
I also have a logo.png next to my Python script.
Is it possible to replace the docx picture ?
If so how ? (Do I delete it in my initial docx and replace it ? with what {{ }} ?)

Thanks for any help, and thanks for the tool :)

Edit : I've tried this
sd = doc.new_subdoc()
sd.add_picture('logo.png', width=Inches(1.25))
context = {'mysubdoc' : sd}
and added {{mysubdoc}} in the docx file
but when I open the generated docx I have an error message from Word and the picture is missing

Pagebreak

Hello

I need to make doc with one template, several pages, in for loop.

When i add pagebreak in template directly, at end of page, but before {% endfor %} tag, with N items i got N pages with template and N blank pages at end.

How can i do this?

Or maybe i can add subdocs in loop in python to add pages?

Page Break SubDoc

Hi,

Is there currently a way to insert a page break after a subdoc? My Subdoc loops though and creates content from a DB, and I want it to put each set of data on a new page.

Editing tables

Hi,
Could you please tell if there's a way to edit tables - add new rows.

Many thanks!

Editing chart

Hi again!
Is there any way to edit chart in the document. It needs the data to be put into the excel file when your rightclick on the graph>edit.
Thank you for awesome python add-on!

Apply cell colors subpage

Is there a way to apply colors to a table in a subpage? For example in the test/test_files/subpage.docx there are no borders or colors applied as part of that table. I tried to use the {% cellbg %} with no luck.

Problem with data containing '< '

Whenever I try to create a document containing a minor sign followed by a space ('< ') I get the following error:

Traceback (most recent call last):
  File "simple.py", line 7, in <module>
    tpl.render(context)
  File "/usr/lib/python2.7/site-packages/docxtpl/__init__.py", line 105, in render
    self.map_xml(xml)
  File "/usr/lib/python2.7/site-packages/docxtpl/__init__.py", line 86, in map_xml
    root.replace(body,etree.fromstring(xml))
  File "src/lxml/lxml.etree.pyx", line 3213, in lxml.etree.fromstring (src/lxml/lxml.etree.c:77697)
  File "src/lxml/parser.pxi", line 1819, in lxml.etree._parseMemoryDocument (src/lxml/lxml.etree.c:116494)
  File "src/lxml/parser.pxi", line 1700, in lxml.etree._parseDoc (src/lxml/lxml.etree.c:115040)
  File "src/lxml/parser.pxi", line 1040, in lxml.etree._BaseParser._parseUnicodeDoc (src/lxml/lxml.etree.c:109165)
  File "src/lxml/parser.pxi", line 573, in lxml.etree._ParserContext._handleParseResultDoc (src/lxml/lxml.etree.c:103404)
  File "src/lxml/parser.pxi", line 683, in lxml.etree._handleParseResult (src/lxml/lxml.etree.c:105058)
  File "src/lxml/parser.pxi", line 613, in lxml.etree._raiseParseError (src/lxml/lxml.etree.c:103967)
lxml.etree.XMLSyntaxError: StartTag: invalid element name, line 1, column 827

I included a template and script to reproduce it in simple.zip.

I peeked several DOCX files which included a '<' char and the XML actually stores the HTML entity instead of the character, so maybe replacing beforehand?

Besides my particular need of using the combination of these chars, I'm pretty sure the lib could be vulnerable to an XML external entities attack.

Strings with Newlines

Great project,

I couldn' t find a way to pass Strings including newline characters (\n or \r) to the template. The newline characters just got replaced by spaces in the output document.

doc = DocxTemplate('mytemplate')
context = {
    'body': 'some text with\nnewline characters\nThx
}
doc.render(context)
doc.save("generated_doc.docx")

In my word template I' m using simple JINJA2 tags like {{ body }}.
Am I doing something wrong?
Greetings

Python3.x encoding in headers and footers

I am having problems with the regex in python3.x in the DocxTemplate(object) due to the function that searches for the xml encoding which begins on line 99. In 3.x, the regex expression in get_headers_footers_encoding(xml) requires xml to be a string object, but it's getting passed as bytes and breaking the expression on line 93.

The traceback is
TypeError: can't use a string pattern on a bytes-like object
python 3.5, 3.4
docxtpl 0.2.2
requirements as spec'd in a clean conda env

My quick workaround is inelegant but is working for python 3.x and shouldn't break the 2.7 compatibility.
The logic to assign the global is not shown, but the temporary workaround begins on line 101 of docxtpl/init.py:

if PY3K:
    xml = xml.decode('utf-8')
encoding = self.get_headers_footers_encoding(xml)
if PY3K:
     xml = self.patch_xml(xml)
else:
     xml = self.patch_xml(xml).decode(encoding)

I assume your testing process includes 3.x and I see that headers and footers have given you plenty of headaches before, which means that it's likely working for you. Have you had problems with this regex traceback? If not, I wonder what going on with my env or package combination. Also, now that this is working for me it's seriously saving me tons of time, so thank you for writing/maintaining it.
PS. The code above has not been run through your test suite, so caveat emptor to any others with the same problem that who hit this issue thread.

XML ilegal chars

Hi there,
is RichText supporting ilegal chars like "&" if not how can I escape them?
Directly in text or?
I had a problem that many english texts in my database have that 'and' sign,
but I didn't found and documentation related to it or I missed some thing.

Thx for time.

Multi Context

Howdy,

I have been playing with this for a couple days, and I am liking it so far. Here is my issue.

Simply put I have a word doc and at the top of my python code I have something like this:

Context = { report_name : "Name XYZ", report_date : "1/2/2222" }

then later in my code using some data from some sql queries I need to have some more data put into the template so I try:

'context = { 'data' : row[1] }'
then if I do:
'doc.render(context)' and save it only one of my contexts works because I am over writing the first context variable. I have also tried to do context1 and context2 but when I render context1 and then context2 I still do not get my data in my output file. Any ideas on how I could accomplish this?

Note that any of these above context statements do work on their own so I know my template variables are working as expected.

Whitespace?

Hi there! First off, your module is fantastic. Second, is there a way to get rid of the whitespace left after the Jinja tags are parsed and removed? Jinja docs suggest {%- tag %}{% endtag -%} but I'm not having much luck with that method.

Any roadmap for adding images/pictures?

Not really an issue as you can imagine, but I wonder if you plan adding option to insert pictures/images into docx documents?

My use case is to generate bunch of reports for different customers and I would like to automate adding customer's logo on each and every new docx document that I am creating from a template.

Cheers,
Milos

Headers and Footers

Hi,

I created a wrapper class that supports headers and footers.
It is not officially support by docx but it works without any problem.

"""
Created : 2016-03-09

@author: Denny Weinberg
"""

__version__ = '1.0.0'

from docxtpl import DocxTemplate as _DocxTemplate

class DocxTemplate(_DocxTemplate):
    """
    This class represents a wrapper class for docxtpl to support headers and footers
    """
    HEADER_URI = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/header"
    FOOTER_URI = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/footer"

    def get_headers_footers_xml(self, uri):
        for relKey, val in self.docx._part._rels.items():
            if val.reltype == uri:
                yield relKey, val._target._blob.decode()

    def build_headers_footers_xml(self,context, uri,jinja_env=None):
        for relKey, xml in self.get_headers_footers_xml(uri):
            xml = self.patch_xml(xml)
            xml = self.render_xml(xml, context, jinja_env)
            yield relKey, xml

    def map_headers_footers_xml(self, relKey, xml):
        self.docx._part._rels[relKey]._target._blob = xml.encode()

    def render(self, context, jinja_env=None):
        super().render(context, jinja_env=jinja_env)

        # Headers
        for relKey, xml in self.build_headers_footers_xml(context, self.HEADER_URI, jinja_env):
            self.map_headers_footers_xml(relKey, xml)

        # Footers
        for relKey, xml in self.build_headers_footers_xml(context, self.FOOTER_URI, jinja_env):
            self.map_headers_footers_xml(relKey, xml)

problem with template path - Compiling exe with pyinstall

Hi!
I'm trying to compile the program into exe with pyinstall.
When I run the program, I get the error that default.docx is not found. I understand that program cannot find my template file and tries to load default template, which is not included into exe. How can i resolve the path to my template problem? At the moment i use such path in the program: tpl=DocxTemplate('c:/QAT/bin/template.docx')

Many thanks!!!

Error is below:

Traceback (most recent call last):
File "", line 1344, in
File "", line 952, in menu
File "", line 1291, in generate_report
File "site-packages\docxtpl__init__.py", line 116, in new_subdoc
File "site-packages\docxtpl__init__.py", line 123, in init
File "site-packages\docx\api.py", line 25, in Document
File "site-packages\docx\opc\package.py", line 116, in open
File "site-packages\docx\opc\pkgreader.py", line 32, in from_file
File "site-packages\docx\opc\phys_pkg.py", line 31, in new
docx.opc.exceptions.PackageNotFoundError: Package not found at 'C:\Users\sp\AppData\Local\Temp_MEI48882\docx\templates\default.docx'

RichText: Keep Word font size and family

Hi,

If I use {{r RichText('abc', bold=True) }} I have my bold text "abc" but I loose my font family and size that I used in the Word Template.

Is there any chance to keep the formatting defined in word, except if I pass it as arguments to the RichText constructor?

header and footer problem

The header and footer will disappear when also using the subdoc at the same time. Any idea to avoid this problem?

Thanks for help in advance and thanks for the great tool.

updating TOC

Hi!
is there any way to update Table of Contents when the file is generated from template?

Thank you!

Optional row in table?

Hi, found this project today. awesome how easy this works. great work!

i wonder if it is possible to have an optional row in a table. this row should only be shown if there is some content. i have tried {% if my_content%} {{my_content}} {% endif %}. the problem is, that there is an empty row in the table if my_content is not in the item.

any workaround on this?

please keep on the great work
dd

|e and newline

|e escapes special XML Charakters... Shouldn't it also handle \r\n?

Table Cell Border

Hello,

I really appreciate what you have created here. It has helped me in a big way with my current project.
I have a question regarding setting table cell border. I know that you have the cellbg option to set the background, but is it possible to somehow change the cell border?

Thank you very much for any help you can offer.

RichText: Adapt the new line handling

In the RichText class we need to replace the line
text = escape(text).replace('\n','<w:br/>')

by
text = escape(text).replace('\r\n', '<w:br/>').replace('\r', '<w:br/>').replace('\n', '<w:br/>')

because we uses sometimes only \r and in this case the first line does not work.

Section breaks change from Next page - Continously

Hi,
Thanks a lot for your package. Its absolutely beautiful to create documents.
I got everything working but I cannot get the section breaks properly working.

The problem is that in my template I have set some Sections -- Next page
but when running the template, It gets magically changed into Sections - continously
and I was wondering what the correct way would be to force page sections? Ideally I would just put all the sections in different documents and merge them but I have no Idea if you can do that with this package.

I don't know how docx-template is treating sections .
IT feels like word is changeing the sections type randomly?

Should I use subdocuments for this? as
My template for one page can be multiple pages long.
As for example it contains the text in this way.

{%p if distributor %}
bla bla bla
{%p else %}
bo bo bo bo
sfdsfdsfdsfsd
{%p endif%}
------ section break - Next page

So then after this i add a section break
but looks like word does not stick to this? It kind of randomly changes this to a sectionbreak - Continously?

So I have four sections

  • Intro page (a cover page with some info (1 page)
  • Brief letter with some info (1 page)
  • Details (Several pages, depends on generated info)
  • Terms and conditions (1 page section with column layout)

As I have quite some text I was hoping I could manage all of this without having
to create a subdocument in my python code.

Is there a way to have 4 different documents, open them as a subdocument and nicely but a master file with the correct page breaks etc?

Its probably a lot but was wondering how others deal with documents with multiple sections. All the rest is working really great.

jinja2.exceptions.TemplateSyntaxError: unexpected char u'&'

I have jinjia2 syntax like: {% if len > 0 %} in the template.

I got the error message: jinja2.exceptions.TemplateSyntaxError: unexpected char u'&' when I tried to convert the docx from template.

I try to change the '>' to 'gt', but it doesn't work. Does any one know the solution?

Inappropriate requirements in setup.py

The documentation requirements in setup.py could do with some tweaking:

  • The sphinx version restriction seems redundant. I have Sphinx 1.3 installed, and it works fine to build the docs. But without manual tweaking of setup.py the <1.3b restriction stops me installing from pip.
  • sphinxcontrib-napoleon isn't used in docs/conf.py, but is mentioned as a requirement. (In fact, with recent sphinx versions, that extension is built in.)

Can`t load images in table or text box

hello,

I develope atomatical report using this docxtpl. I don`t know how to upload Image file using jinja2, so My image add function is mixed jinja2 and python-docx library function.

When i put lot`s of image files using jinja2, tag MsOffice(2010) send Error message. Message is not english, but that error message means....

"cant open 'report.docx' file becaus something wrong in files"

So i try some test. 2 or 3 image can be added in textbox. but when i try to upload more images, report send same message.
(not onlytextbox but also tables, too)

Here`s my Testing code and docx template file.
(python 3.5.2)
please check and, help why it happened

Thanks!

reporttest.txt
test_template.docx
result.docx

Richtext Styles Not being Applied

Hi, just wanted to say that your lib is fantastic, but i appear to be having an issue. It appears that if the style contains a space or certain characters, the style isnt applied in the output file. I was just wondering if there was a work around for this? Many Thanks. Example below:
rt.add(tag.text , style='Subtle Reference')

Headers, footers tags

Nor really an issue. I was trying to generate a doc using a template containing jinja tags in a header and it turned out that those tags were not filled in with my values. Any ideas?

Apply or keep a paragraph style using subdoc()?

I have a template with {{p IC2}} as a tag. The tag has a custom style applied to it in the template, such as bullet, indent, font size, etc. I run the following code using the subdoc() function. The text successfully replaces the tag but the style is lost. Instead of the custom style, the paragraph has the Normal style applied. Here is the code, which clearly is a reduced version of your subdoc.py example.


from docxtpl import DocxTemplate
tpl=DocxTemplate('test_tpl.docx')
sd = tpl.new_subdoc()
p = sd.add_paragraph('This is the text for IC2.')
context = {
'IC2' : sd,
}
tpl.render(context)
tpl.save('test.docx')


I can insert text following the example given inrichtext.py and using {{r IC2}} as the tag. The inserted text will properly inherit the paragraph style but new lines (separated by \n) do not. For example, the line will be properly indented according to the style but will not have the bullet that is also part of the style.

docxtpl doesn't work on Python 3

Hey, I use Python 3.4 and docxtpl doesn't work there...

Fortunately, fixing it is not difficult :

    def get_xml(self):
        return etree.tostring(self.docx._element.body, pretty_print=True)

becomes

    def get_xml(self):
        return etree.tostring(self.docx._element.body, encoding=str, pretty_print=True)

but that breaks compatibility with python 2.7 :-(

thanks for the nice code, it's very powerful !

Jinja2 Image

Love the library. I was wondering if there is any thoughts on adding template for embedding images?

Are nested loops possible?

Is it possible to nest loops in the template? If so, is there a special syntax that is necessary?

When I try to use nested for loops, I am getting this error:
Encountered unknown tag 'endfor'.

This is essentially what I am trying to do:

{% for author in authors %}
    {% for book in author.books %} 
        {{ author.name }} {{ book.title }}
    {% endfor %}
{% endfor %}

I tried doing this with variations of {%p but that did not seem to help.

tr endfor is not always recognized

I have a table that looks like this:
image

And by the love of Zeus, it will not let me process it. It keeps saying "TemplateSyntaxError: Unexpected end of template. Jinja was looking for the following tags: 'endfor' or 'else'. The innermost block that needs to be closed is 'for'."

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.