Re: Problem to complète the xml template

23 views
Skip to first unread message

Jirka Vejrazka

unread,
Jul 5, 2012, 3:42:06 AM7/5/12
to django...@googlegroups.com
> Hello,
> http://cdm-fr.fr/2006/schemas/CDM-fr.xsd" language="fr-FR">
> {% if formations %}
> <cdm:contacts>
> <cdm:contactData>

Hi there,

you probably want to follow your {% if formations %} statement with:
{% for formation in formations %}

Check Django template documentation again - you're moving along the
right path, but your template is missing the loop across individual
formations.

HTH

Jirka

bruno desthuilliers

unread,
Jul 5, 2012, 7:06:11 AM7/5/12
to django...@googlegroups.com
On Wednesday, July 4, 2012 8:12:50 PM UTC+2, nef wrote:
Hello,

Bonjour
 
I want to cry a function allowing me to complete a template *. Xml. May I have a problem with the passage of the object render_to_response. In short here is my code. In fact, I do not know how to return an object that can permattre me to complete my template automatically.
I am using django 1.1 and Python 2.6
Function writes to the file views.py

def main_formation(request, formation_id):
    formations = Formation.objects.get(id=formation_id)

You name your variable "formations" (plural) but your query returns a single Formation instance.
 
    variables = RequestContext(request, {
        'formations': formations
        })
    return render_to_response('saisie/formation.xml', variables)

This is mu xml template

(snip headers)
 
  {% if formations %}
       <cdm:contacts>
<cdm:contactData>
<cdm:adr> 
<cdm:locality>{{ formation.ville }}</cdm:locality>

You named the variable "formations" (plural) but you're trying to access an indexistant "formation" (singular) object. This will eval to the settings.TEMPLATE_STRING_IF_INVALID value, which by default is an empty string. For developpment, it might help to set TEMPLATE_STRING_IF_INVALID to a more obvious value (I personnaly use "XXX:INVALID").
 

Reply all
Reply to author
Forward
0 new messages