posts - 431,  comments - 344,  trackbacks - 0
          公告
           Don't Repeat Yourself
          座右銘:you can lose your money, you can spent all of it, and if you work hard you get it all back. But if you waste your time, you're never gonna get it back.
          公告本博客在此聲明部分文章為轉摘,只做資料收集使用。


          微信: szhourui
          QQ:109450684
          Email
          lsi.zhourui@gmail.com
          <2009年4月>
          2930311234
          567891011
          12131415161718
          19202122232425
          262728293012
          3456789

          留言簿(15)

          隨筆分類(1019)

          文章分類(3)

          文章檔案(21)

          收藏夾

          Link

          好友博客

          最新隨筆

          搜索

          •  

          積分與排名

          • 積分 - 861073
          • 排名 - 44

          最新評論

          閱讀排行榜

          It's a way of generating a valid URL, generally using data already obtained. For instance, using the title of an article to generate a URL. I'd advise to generate the slug, using a function, given a title (or other piece of data), rather than setting it manually.

          An example:

          <title> The 46 Year Old Virgin </title>
          <content> LOL!!! What a loser heh </content>
          <slug> the-46-year-old-virgin </slug>

          Now let's pretend that we have a Django model such as:

          class Article():
              title
          = models.CharField(max_length=100)
              content
          = models.TextField(max_length=1000)
              slug
          = models.SlugField(max_length=40)

          How would you reference this object with a URL, with a meaningful name? You could use Article.id so the URL would look like this:

          www.example.com/Article/23

          Or, you could reference the title like so:

          www.example.com/article/The 46 Year Old Virgin

          Problem is, spaces aren't valid in URLs, they need to be replaced by %20 which is ugly, making it the following:

          www.example.com/article/The%2046%20Year%20Old%20Virgin

          That's not solving our meaningful URL. Wouldn't this be better:

          www.example.com/article/the-46-year-old-virgin

          That's a slug. 'the-46-year-old-virgin'. All letters are downcased and spaces are replaced by hyphens '-'. See the URL of this very webpage for an example!

          posted on 2009-04-28 14:07 周銳 閱讀(226) 評論(0)  編輯  收藏 所屬分類: Python
          主站蜘蛛池模板: 贵州省| 油尖旺区| 贵溪市| 新化县| 江川县| 余姚市| 衡阳市| 从化市| 仁化县| 静安区| 泰顺县| 同江市| 武强县| 宜川县| 夹江县| 东乌珠穆沁旗| 普宁市| 阿克| 肥城市| 吉木萨尔县| 绿春县| 怀宁县| 南平市| 娱乐| 大渡口区| 高邮市| 桑日县| 德钦县| 南投县| 德江县| 东光县| 密山市| 湖南省| 咸阳市| 扶风县| 尉氏县| 苏尼特左旗| 舒兰市| 奈曼旗| 连州市| 游戏|