Help with implementing dynamic views/models
This may seem like a very simple question and I have just missed the
answer in the piles of documentation and tutorials that I've read over
the past two days. I'm new to Django and trying to implement an
internal site at work, and I'm the only Python/Django person we have,
so this is all on me.
What I am doing is this: I have a set of .html files, templates, which
are named testn.html (i.e. test1.html, test2.html, etc) Each template
extends base.html, but they each have at least 2 divs that I need to
populate with HTML that is entered in the admin interface and stored
in the Page model. What I need to do is this:
from the url parse what test is being requested:
url(r'^test(\d{1})/$', test),
cal the test view:
def test(request, testn):
try:
testn = str(testn)
return direct_to_template(request, template="test%s.html" %
testn)
except ValueError:
raise Http404()
And then return the template, but with the correct object attached to
it, filtered by name. I can't find a way to do this, all that I can
find are ways that make me grab all the objects (and where do I do
this? In models.py or views.py? There are conflicting thoughts on
this). I really just need to grab the one object, and if it has the
fields I need, to populate the template with them. Is there an easy
way to do this that won't require me to loop over all objects?
Thank you so much for any help or insight!
--Laura C.
--
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.
0 Comments:
Post a Comment
Subscribe to Post Comments [Atom]
<< Home