slug

Why do some websites add “Slugs” to the end of URLs? [closed]

江枫思渺然 提交于 2019-11-26 12:20:03
问题 Many websites, including this one, add what are apparently called slugs - descriptive but as far as I can tell useless bits of text - to the end of URLs. For example, the URL the site gives for this question is: https://stackoverflow.com/questions/47427/why-do-some-websites-add-slugs-to-the-end-of-urls But the following URL works just as well: https://stackoverflow.com/questions/47427/ Is the point of this text just to somehow make the URL more user friendly or are there some other benefits?

String slugification in Python

主宰稳场 提交于 2019-11-26 12:05:24
问题 I am in search of the best way to \"slugify\" string what \"slug\" is, and my current solution is based on this recipe I have changed it a little bit to: s = \'String to slugify\' slug = unicodedata.normalize(\'NFKD\', s) slug = slug.encode(\'ascii\', \'ignore\').lower() slug = re.sub(r\'[^a-z0-9]+\', \'-\', slug).strip(\'-\') slug = re.sub(r\'[-]+\', \'-\', slug) Anyone see any problems with this code? It is working fine, but maybe I am missing something or you know a better way? 回答1: There

Turn a string into a valid filename?

孤街浪徒 提交于 2019-11-26 11:58:33
I have a string that I want to use as a filename, so I want to remove all characters that wouldn't be allowed in filenames, using Python. I'd rather be strict than otherwise, so let's say I want to retain only letters, digits, and a small set of other characters like "_-.() " . What's the most elegant solution? The filename needs to be valid on multiple operating systems (Windows, Linux and Mac OS) - it's an MP3 file in my library with the song title as the filename, and is shared and backed up between 3 machines. S.Lott You can look at the Django framework for how they create a "slug" from

Best way to generate slugs (human-readable IDs) in Rails

五迷三道 提交于 2019-11-26 11:51:37
问题 You know, like myblog.com/posts/donald-e-knuth. Should I do this with the built in parameterize method? What about a plugin? I could imagine a plugin being nice for handling duplicate slugs, etc. Here are some popular Github plugins -- does anyone have any experience with them? http://github.com/rsl/stringex/tree/master http://github.com/norman/friendly_id/tree/master Basically it seems like slugs are a totally solved problem, and I don\'t to reinvent the wheel. 回答1: I use the following,

How to make Django slugify work properly with Unicode strings?

安稳与你 提交于 2019-11-26 08:47:13
问题 What can I do to prevent slugify filter from stripping out non-ASCII alphanumeric characters? (I\'m using Django 1.0.2) cnprog.com has Chinese characters in question URLs, so I looked in their code. They are not using slugify in templates, instead they\'re calling this method in Question model to get permalinks def get_absolute_url(self): return \'%s%s\' % (reverse(\'question\', args=[self.id]), self.title) Are they slugifying the URLs or not? 回答1: There is a python package called unidecode

How can I create a friendly URL in ASP.NET MVC?

允我心安 提交于 2019-11-26 07:58:36
问题 How do I generate friendly URLs within the ASP.NET MVC Framework? For example, we\'ve got a URL that looks like this: http://site/catalogue/BrowseByStyleLevel/1 The 1 is Id of the study level (Higher in this case) to browse, but I\'l like to reformat the URL in the same way StackOverflow does it. For example, these two URLs will take you to the same place: https://stackoverflow.com/questions/119323/nested-for-loops-in-different-languages https://stackoverflow.com/questions/119323/ EDIT: The

How do I create a slug in Django?

感情迁移 提交于 2019-11-26 06:52:13
问题 I am trying to create a SlugField in Django. I created this simple model: from django.db import models class Test(models.Model): q = models.CharField(max_length=30) s = models.SlugField() I then do this: >>> from mysite.books.models import Test >>> t=Test(q=\"aa a a a\", s=\"b b b b\") >>> t.s \'b b b b\' >>> t.save() >>> t.s \'b b b b\' I was expecting b-b-b-b . 回答1: You will need to use the slugify function. >>> from django.template.defaultfilters import slugify >>> slugify("b b b b") u'b-b

Generate SEO friendly URLs (slugs)

梦想的初衷 提交于 2019-11-26 06:29:18
问题 Definition From Wikipedia: A slug is the part of a URL which identifies a page using human-readable keywords. To make the URL easier for users to type, special characters are often removed or replaced as well. For instance, accented characters are usually replaced by letters from the English alphabet; punctuation marks are generally removed; and spaces (which have to be encoded as %20 or +) are replaced by dashes (-) or underscores (_), which are more aesthetically pleasing. Context I

URL Slugify algorithm in C#?

本秂侑毒 提交于 2019-11-26 06:16:05
问题 So I have searched and browsed through the slug tag on SO and only found two compelling solution: Slugify and Character Transliteration in C# How to convert super- or subscript to normal text in C# Which are but partial solution to the problem. I could manually code this up myself but I\'m surprised that there isn\'t already a solution out there yet. So, is there a slugify alrogithm implementation in C# and/or .NET that properly address latin characters, unicode and various other language

Turn a string into a valid filename?

让人想犯罪 __ 提交于 2019-11-26 02:39:51
问题 I have a string that I want to use as a filename, so I want to remove all characters that wouldn\'t be allowed in filenames, using Python. I\'d rather be strict than otherwise, so let\'s say I want to retain only letters, digits, and a small set of other characters like \"_-.() \" . What\'s the most elegant solution? The filename needs to be valid on multiple operating systems (Windows, Linux and Mac OS) - it\'s an MP3 file in my library with the song title as the filename, and is shared and