[Django]-Dynamic SEO-friendly URLs

1👍

✅

if you have a database entity corresponding to one page (e.g. vehicle view and a Vehicle DB table), you can use define get_absolute_url() method in the model class.

more on get_absolute_url: http://docs.djangoproject.com/en/dev/ref/models/instances/#get-absolute-url

e.g:

class Vehicle(models.Model):
    name = ...
    year = ...
    fancy_stuff = ...

    def get_absolute_url(self):
        return u'%s-%s-%s' % (self.year, self.name, self.fancy_stuff)

whenever you are working with vehicle objects, you can get the full ‘seo-friendly’ url …


my naive approach for the filter would be:

  • write an appropriate regex in urls.py, either passing on a whole string value to a view function for further dispatch or designing the regex to be consistent and structured ..

    (r'^filter/(?P<name>[a-zA-Z]+)/(?P<year>\d+)/(?P<type>\d+)/$)', ...
    
  • make the appropriate DB queries

  • display ..

Leave a comment