Dynamic SEO-friendly URLs

人走茶凉 提交于 2019-12-05 13:13:01

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 ..
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!