Best new restaurants 2010: ho" />
开发者

django link format words joined with hypens

href="http://www.torontolife.com/daily/daily-dish/restauranto/2010/03/10/best-new-restaurants-2010开发者_StackOverflow社区-james-chatto-names-five-honourable-mentions/">Best new restaurants 2010: honourable mentions

does django have built in mechanism to format links above i mean words joined with hypens

how can i achieve this ?


At a lower level, Django provides a function to transform an arbitrary string into a slug:

>>> from django.template.defaultfilters import slugify
>>> print slugify('Hello, World!')
hello-world

And because slugify is a default template filter, you can always use this in your templates like so:

{{ foo.name|slugify }}


The "words joined with hypens" thing you're talking about is known as a slug. It is a unique string identifier used to access a specific resource.

Django does provide support for using this type of resource-to-URL mapping.

  • There is a built in SlugField which you can use to store the unique string for each resource
  • Django's url routing scheme supports "accepting" slugs

To get started doing something like this, you're going to need to understand how the Django framework works overall. I'd recommend checking out the Django Book. It includes a full (and free) tutorial to get you started on how to use these types of things.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜