Note
If you're using Django's
render_to_response()<https://docs.djangoproject.com/en/dev/topics/http/shortcuts/#django.shortcuts.render_to_response>
shortcut
to populate a template with the contents of a dictionary, your template
will be passed a Context instance by default (not a RequestContext). To use
a RequestContext in your template rendering, pass an optional third
argument to
render_to_response()<https://docs.djangoproject.com/en/dev/topics/http/shortcuts/#django.shortcuts.render_to_response>:
a RequestContext instance. Your code might look like this:
def some_view(request):
# ...
return render_to_response('my_template.html',
my_data_dictionary,
context_instance=RequestContext(request))
https://docs.djangoproject.com/en/dev/ref/templates/api/
L'utilisation d'un dictionnaire fusionné avec le context ne me semble pas
approprié, je ne l'ai jamais vu employé comme cela, mais je n'ai pas la
science infuse ...
def main_formation(request, formation_id):
formations = Formation.objects.get(id=formation_id)
variables = RequestContext(request, {
'formations': formations
})
return render_to_response('saisie/formation.xml', variables)
Le 4 juillet 2012 20:35, M. Namgyal Brisson <
[email protected]> a écrit :
> Bonsoir,
>
> La fonction :
>
> def main_formation(request, formation_id):
> formations = Formation.objects.get(id=formation_id)
> variables = RequestContext(request, {
> 'formations': formations
> })
> return render_to_response('saisie/formation.xml', variables)
>
> comporte à mon sens quelques erreurs!
>
> la fonction, sauf erreur de ma part, 'render_to_response()' est mal
> utilisée.
>
> Elle prend les paramètres
>
> 1. template -> str
>
> 2. dictionnaire de données -> dict
>
> 3. (optionnel) le RequestContext ou le mime type
>
> cf doc, qui est d'ailleurs très bien renseignée à ce sujet !!!
>
>
> https://docs.djangoproject.com/en/dev/topics/http/shortcuts/#django.shortcuts.render_to_response
>
>
> Le 4 juil. 2012 19:42, "Eric Francis" <[email protected]> a écrit :
>
> Bonjour,
>> Je souhaite écrie une fonction me permettant de remplir un template xml.
>> Mai j'ai des problème au niveau du passage de l'objet httpReponse. Bref
>> voici mon ode
>> Fonction écrit dans le fichier views.py
>>
>> [i]
>> def main_formation(request, formation_id):
>> formations = Formation.objects.get(id=formation_id)
>> variables = RequestContext(request, {
>> 'formations': formations
>> })
>> return render_to_response('saisie/formation.xml', variables)
>> [/i]
>>
>> Voici mon fichier template que je souhaite remplir
>>
>> [i]
>> <cdm:CDM xmlns:cdm="http://cdm-fr.fr/2006/CDM-frSchema"
>> xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
>> xsi:schemaLocation="http://cdm-fr.fr/2006/CDM-frSchema
>> [url=
>> http://cdm-fr.fr/2006/schemas/CDM-fr.xsd\]http://cdm-fr.fr/2006/schemas/CDM-fr.xsd\
>> "[/url]
>> language="fr-FR">[/i]
>>
>> [i]{% if formations %}
>> <cdm:orgUnitName>
>> <cdm:text language="fr-FR">[b] {{ formation.etablissement
>> }}[/b]
>> </cdm:text>
>> </cdm:orgUnitName>
>> <cdm:orgUnitAcronym>[b]{{ formation.sigle
>> }}[/b]</cdm:orgUnitAcronym>
>> <cdm:contacts>
>> <cdm:contactData>
>> <cdm:adr>
>> <cdm:locality>[b] {{ formation.ville
>> }}[/b] </cdm:locality>
>> <cdm:country>[b] {{ formation.pays }}[/b]
>> </cdm:country>
>> </cdm:adr>
>> </cdm:contactData>
>> </cdm:contacts>[/i]
>>
>> [i]</cdm:CDM>
>> {% endif %}
>> [/i]
>> Merci d'avance à toute personne pouvant me donné quelques indications.
>> _______________________________________________
>> django mailing list
>> [email protected]
>> http://lists.afpy.org/mailman/listinfo/django
>>
>
--
*App Concept Lab*
*app-concept-lab.fr ( à venir )*
*Vos applications ont du talent !*
*M Brisson Namgyal*
*Mobile* *06.36.91.35.30*
*Fixe* *09.51.59.30.45**
**Mail** [email protected]**
***
_______________________________________________
django mailing list
[email protected]
http://lists.afpy.org/mailman/listinfo/django