在od中使用slug有什么用

2024-09-24 22:24:59 发布

您现在位置:Python中文网/ 问答频道 /正文

什么是slug以及为什么使用它。我很困惑。有人能帮我吗。塔克斯

 <p><a t-attf-href="/academy/{{ slug(teacher) }}">
     <t t-esc="teacher.name"/></a>

Tags: namehrefslugteacheracademyescattf
2条回答

websitepython文件中所述。在

Transform a string to a slug that can be used in a url path.

This method will first try to do the job with python-slugify if present. Otherwise it will process string by stripping leading and ending spaces, converting unicode chars to ascii, lowering all chars and replacing spaces and underscore with hyphen "-".

我认为它可以从字符串中删除特殊字符。在

在“加载项”>;“web”>;“静态”>;“lib”>;下划线.string.js在

slugify: function(str) {
      if (str == null) return '';

      var from  = "ąàáäâãåæăćęèéëêìíïîłńòóöôõøśșțùúüûñçżź",
          to    = "aaaaaaaaaceeeeeiiiilnoooooosstuuuunczz",
          regex = new RegExp(defaultToWhiteSpace(from), 'g');

      str = String(str).toLowerCase().replace(regex, function(c){
        var index = from.indexOf(c);
        return to.charAt(index) || '-';
      });

      return _s.dasherize(str.replace(/[^\w\s-]/g, ''));
    },

相关问题 更多 >