On Tue, Apr 14, 2009 at 11:19 AM, nixon66 <nixon....@gmail.com> wrote:
> > Alex, > > Ok, I'm going to ram my head into a wall now. Seriously thanks. > > On Apr 14, 11:03 am, Alex Gaynor <alex.gay...@gmail.com> wrote: > > On Tue, Apr 14, 2009 at 11:01 AM, nixon66 <nixon....@gmail.com> wrote: > > > > > I have this model with an get_absolute_url method. > > > > > class Country(models.Model): > > > country_cd = models.CharField(max_length=2, primary_key=True) > > > country = models.CharField(max_length=80, blank=True) > > > slug = models.CharField(max_length=80, blank=True) > > > class Meta: > > > db_table = u'country' > > > > > def __unicode__(self): > > > return self.country > > > > > def get_absolute_url(self): > > > return 'lobby/country/%s/' % self.slug > > > > > using this in a template > > > > > {% for country in country_list %} > > > > > <li><a href ="{{country.get_absolute_url }}">{{ country.country }}</ > > > a></li> > > > > > gets me a list of countries. > > > > > *Algeria > > > *Australia > > > *Afghanistan > > > etc > > > > > But when I put my mouse over the links or click on the links instead > > > of getting > > > 'http://localhost:8000/lobby/country/algeria'for<http://localhost:8000/lobby/country/algeria%27for> > > > example, I get > > > 'http://localhost:8000/lobby/country/lobby/country/egypt'. Anyone > > > have an idea of why its adding the extra text onto the url? I've done > > > this before and have not have a problem. In fact the code and > > > templates are from another app and they work just fine. > > > > It's because your urls don't start with a / so they are relative to your > > current location. > > > > 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 > > > I'd also reccomend you use reverse/the permalink decorator in place of handcrafting the URL as it makes your apps easier to reuse and more flexible: http://docs.djangoproject.com/en/dev/ref/models/instances/?from=olddocs#get-absolute-url 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 -~----------~----~----~----~------~----~------~--~---