Hi, people.

Thanks a lot for the indications. Will work on them and sure will find
a way to implement what I am looking for :-)

Take care.

Jean

On Oct 16, 9:39 am, Malcolm Tredinnick <[EMAIL PROTECTED]>
wrote:
> On Thu, 2008-10-16 at 00:19 -0700, JFQueralt wrote:
> > Hi, James.
>
> > Does that imply I can use Pythong´s XML manipulation libraries in
> > Django blocks?
>
> > There has to be a way to retrieve information fron a file in Django (I
> > ´ve seen official docs on it).
> > XML is nothing than a structured data file so there should be a way to
> > retrieve a value and use it in a template.
>
> I think you're missing something here. Planning to do complex data
> manipulation in templates is almost always the wrong place. The view
> functions -- the pure Python code -- is where your data manipulations
> take place and templates are just a way of specifying how the objects
> passed to them are converted to strings (since the result of rendering a
> template is a string).
>
> There are limited ways to convert any Python object into a string in a
> template. In decreasing order of complexity, they are:
>
>         1) Pass it to a template tag.
>         2) Pass the object through a template filter
>         3) Call a method on the object that takes no arguments
>         4) Look up an attribute or dictionary key on the object.
>         5) Call the objects __unicode__ or __str__ method (this is
>         essentially a special case of point 3, but it's what happens
>         automatically when you put "{{ some_var }}" into a template).
>
> So there's not really a question of passing "an XML file" to a template
> and then working with it in the template. You only pass Python objects
> of some variety to templates. Instead, work with the XML file in the
> view (using Python's existing XML libraries, as James and Russell have
> mentioned) and convert it to one or more Python objects that can then be
> rendered in the templates using the one of the above options.
>
> You could write a template tag that took a Python file object or a
> variable containing the name of the file and then used the Python code
> behind the template tag to read in the file and do whatever you want
> with it. In some circumstances, that might be a useful idiom. However,
> if you're just starting out with Django, it will no doubt be easier to
> start by doing the initial processing entirely in the view, so that you
> only have to look at options 3, 4 and 5 above. Then, after you are
> comfortable with that (and right now you seem to have some confusion
> about what "Django" means in terms of what it does for you), you might
> be able to abstract out somethings into template tags if that makes
> things easier (it's not necessarily a given that it will make things
> easier, either).
>
> Regards,
> Malcolm
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to