django_friendlyurls

Use friendly URLs with Django
Download

django_friendlyurls Ranking & Summary

Advertisement

  • Rating:
  • License:
  • Artistic License
  • Price:
  • FREE
  • Publisher Name:
  • Jeff Tchang
  • Publisher web site:
  • http://github.com/tachang/

django_friendlyurls Tags


django_friendlyurls Description

django_friendlyurls is a Django app allows you to create URLs that directly return views.There is no 302 Redirect.The most common use case is that you have URLs which return user profiles such ashttp://www.example.com/user/1Friendly URLs allow you to create a URL so that the user can also be accessed by going to:http://www.example.com/jeffThe key is that the address bar in the browser does not change to http://www.example.com/user/1The web server returns the same HTML document as http://www.example.com/user/1FlowThe application looks up the string 'jeff' If it finds a friendly url match it will read out the absolute_path and attempt to resolve it by putting it through the URL resolver a 2nd time.If it finds a resolution it will return that view.UsageHere is an example of how to implement friendly_urls for a user:I put this in models.py:from django.contrib.contenttypes import genericfrom friendlyurls import UrlMappingfrom django.contrib.auth.models import Userdef get_absolute_url(self): return u'/user/%s' % self.idUser.add_to_class('friendly_urls', generic.GenericRelation(UrlMapping))User.get_absolute_url = get_absolute_urlThis basically monkey patches the User model to add a field. You can then douser = User.objects.get(pk=1)user.friendly_urls.all()This will get a list of all the friendly urls.You shouldn't have to monkey patch all the models.Problems / QuestionsDon't forget to run syncdb because friendlyurls creates a table to store the URL mappings.Additional SettingsFRIENDLYURLS_IGNORE_CASE - Set this to True if you want to ignore the case when trying to find a path. Default: FalseProduct's homepage


django_friendlyurls Related Software