On Sun, Apr 5, 2009 at 3:30 PM, zayatzz <alan.kesselm...@gmail.com> wrote:
> > Okay.. the problem was what i suspected, but i thought, that if i > filter the results and get object by its id, then it would be ok, > since im getting single object. > > Alan. > > On Apr 5, 10:25 pm, Alex Gaynor <alex.gay...@gmail.com> wrote: > > On Sun, Apr 5, 2009 at 3:23 PM, zayatzz <alan.kesselm...@gmail.com> > wrote: > > > > > Hello > > > > > I have created app for public view or well.. the whole site actually, > > > but its somehow not working. > > > > > I have this in views.py > > > > > def index(request): > > > lpl = lang.objects.filter(id=1) > > > t = loader.get_template('front/index.html') > > > c = Context({ > > > 'lpl': lpl > > > }) > > > return HttpResponse(t.render(c)) > > > > > And this in index.html : > > > > > {% if lpl %} > > > <html> > > > <head><title>{{ lpl.title }}</title></head> > > > <body> > > > <h1>{{ lpl.name }}</h1> > > > </body> > > > </html> > > > {% else %} > > > <h1>crap</h1> > > > {% endif %} > > > > > For a while i was getting crap, until i copy pasted code from > > > example... now im getting just this in browser: > > > > > <html> > > > <head><title></title></head> > > > <body> > > > <h1></h1> > > > </body> > > > </html> > > > > > So obviously i dont know how to use the data from the model and > > > perhaps im phrasing the question both wrong here and in my searches, > > > because i have not been able to find answer in groups or web. > > > > > Alan > > > > Your issue here is `lpl` is a QuerySet, not a lang object, when you want > > more than one object you use .filter and then iterate over it using the > for > > tag. However, when you want a single item you should ues .get(), so > > lang.objects.get(id=1). > > > > Alex > > > > -- > > "I disapprove of what you say, but I will defend to the death your right > to > > say it." --Voltaire > > "The people's good is the highest law."--Cicero > > > Django doesn't know you have a single object, all it sees is that you have a queryset. Just like if you have a list with only one object you can't pretend that it's the same as the one object: [obj] != obj. Alex -- "I disapprove of what you say, but I will defend to the death your right to say it." --Voltaire "The people's good is the highest law."--Cicero --~--~---------~--~----~------------~-------~--~----~ 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+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~----------~----~----~----~------~----~------~--~---