Tuesday, December 27, 2011

Re: render_to_response pointing to multiple templates

I am new to Django as well - but in answer to your second question,
you'll need to create a views.py within the app and register the url
in urls.py in the root. Then you can pull in variables from your app
into the template. For example, if you have a Places class which
includes a name and address, your template could read:

{% for p in places%}
<h1>{% p.name %}</h1>
<p>{% p.address %}</p>
{% endfor %}

I recommend going through the "Writing Your First Django App"
tutorial: https://docs.djangoproject.com/en/dev/intro/tutorial01/ -
it's very helpful and gives a great overview.

On Nov 8, 1:44 pm, "jay K." <jay.developer2...@gmail.com> wrote:
> Hello, Tom
>
> thanks for your answer
>
> I believe it can be done like the way you suggested
>
> I should clarify that I am new to django and have no web developing
> background, so
> my questions may sound a bit silly sometimes
>
> I got another one, if you dont mind
>
> how can I retrieve information on a template, such as name and url inside
> a view? I'd like to use it to differentiate between templates and
> use logic to pick the template I want to render
>
> again, Tom, thanks for your assistance
>
>
>
>
>
>
>
> On Mon, Nov 7, 2011 at 2:04 PM, Tom Evans <tevans...@googlemail.com> wrote:
> > On Mon, Nov 7, 2011 at 3:59 PM, jay K. <jay.developer2...@gmail.com>
> > wrote:
> > > hi, Tom
>
> > > thanks for the reply
>
> > > what I actually want to do is to
> > > list several templates in the render_to_response
> > > function and be able to choose which one to use
>
> > > can I choose which template to use?
>
> > > thanks again, and let me know if my question is clear enough
>
> > Of course you can; use logic in your view to decide which template to
> > render, and call render_to_response with that template name… I must be
> > missing something?
>
> > Cheers
>
> > Tom
>
> > --
> > 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
> > django-users+unsubscribe@googlegroups.com.
> > For more options, visit this group at
> >http://groups.google.com/group/django-users?hl=en.

--
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 django-users+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

No comments:

Post a Comment