Note that there are some explanatory texts on larger screens.

plurals
  1. POString causes rendering exception with utf-8 defined
    primarykey
    data
    text
    <p>One of my template tags should return a list of links; most of the elements get their name from the database with the exception of one, which I'll hardcode because it will never change.</p> <pre><code>lista_menu = '&lt;ul class="menu"&gt;\n\ &lt;li&gt;&lt;a href="' + reverse('profileloja', args=(s_loja,)) + '"&gt;' + \ loja.nome.title() + '&lt;/a&gt;&lt;/li&gt;\n&lt;li&gt;&lt;a href="' + reverse('index', args=(s_loja,)) + \ '"&gt;' + 'Página principal' + '&lt;/a&gt;&lt;/li&gt;\n' </code></pre> <p>The string 'Página principal' causes the following error:</p> <p>TemplateSyntaxError at /teste/painel/</p> <p>Caught an exception while rendering: ('ascii', 'P\xc3\xa1gina principal', 1, 2, 'ordinal not in range(128)')</p> <p>If I define the string as unicode(u'Página...') it works fine, but I don't understand why. Shouldn't django know how to work with this after I define # -<em>- coding: utf-8 -</em>- on the top of my code?</p> <p>Edit: if I define a simple tag that returns a variable with the same string('Página principal') it works fine. So why is this case different that forces me to define the string as unicode?</p> <p>Edit2: FULL TAG</p> <pre><code>@register.simple_tag def menupainel(s_loja): def listapaginas(paginfo_menu): lista_menu = '' for pagina in paginfo_menu: lista_menu += '&lt;li&gt;&lt;a href="' + \ reverse('painel_paginfo', args=(pagina.loja, pagina.id))+ \ '"&gt;' + pagina.titulo.title() + '&lt;/a&gt;&lt;/li&gt;\n' lista_menu += '&lt;li class="opcoes_objecto"&gt;&lt;a href="' + \ reverse('editpaginfo', args=(pagina.loja, pagina.id)) + \ '"&gt;' + pagina.titulo.title() + '&lt;/a&gt;&lt;/li&gt;\n' lista_menu += '&lt;li class="opcoes_objecto"&gt;&lt;a href="' + \ reverse('delpaginfo', args=(pagina.loja, pagina.id)) + \ '"&gt;' + pagina.titulo.title() +'&lt;/a&gt;&lt;/li&gt;\n' return lista_menu loja = get_object_or_404(Loja, slug=s_loja) menus = loja.menus.all() paginfo_sem_menu = PaginaInfo.objects.filter(loja=loja).\ filter(publico=True).filter(menu=None) lista_menu = '&lt;ul class="menu"&gt;\n\ &lt;li&gt;&lt;a href="' + reverse('profileloja', args=(s_loja,)) + '"&gt;' + \ loja.nome.title() + '&lt;/a&gt;&lt;/li&gt;\n&lt;li&gt;&lt;a href="' + reverse('index', args=(s_loja,)) + \ '"&gt;' + u'Página principal' + '&lt;/a&gt;&lt;/li&gt;\n' for menu in menus: paginfo_menu = menu.paginasinfo.exclude(slug='index') if paginfo_menu: lista_menu += '&lt;li id="titulo"&gt;' + \ menu.nome.title() + '&lt;/li&gt;\n' + \ listapaginas(paginfo_menu) if paginfo_sem_menu: lista_menu += listapaginas(paginfo_sem_menu) lista_menu += '&lt;/ul&gt;' return lista_menu </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload