On Fri, 2007-12-14 at 23:29 +0100, Florian Lindner wrote: > Hello, > I have two question regarding get_absolute_url: > > 1) I have the template code: > > {% for entry in object_list %} > <h3><a href="{{ entry.get_absolute_url }}"> {{ entry.title }}</a></h3> > {% endfor %} > > It's called from a .generic.list_detail.object_list. My > get_absolute_url is implemented in my model: > > class BlogEntry(Model): > def get_absolute_url(self): > return self.id > > but the link in the template is always http://localhost:8000/blog/ > where blog is my application name and which is also the URL used to > get to the template above. I can even return anything (like a constant > string) but it's not being taken into account, the link is also the > same. What is wrong there? > > 2) As the name says get_absolute_url should always return a absolute > URL (which I understand is a complete URL). Is there a standard way to > produce such a URL? For example I need to my server (here is localhost: > 8000) and the path to application (blog/).
I'm not sure what's going on with the first point. I'd try raising an exception in that method, though, or writing out to sys.stderr, just to confirm the method is actually being called without error. With regards to your second question, the name is a little bit of a misnomer, resulting from a misunderstanding in the prehistoric days of Django. Changing it would cause massive upheaval, so we can live with the misnaming. The scheme ("http" or "https") and site domain name will be appended to the front of whatever get_absolute_url() returns, so you need to return everything after the domain name (starting with a slash). So, it's not really 'absolute'. Regards, Malcolm -- Telepath required. You know where to apply... http://www.pointy-stick.com/blog/ --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---