Python django.template.defaultfilters.striptags() Examples
The following are 12
code examples of django.template.defaultfilters.striptags().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
django.template.defaultfilters
, or try the search function
.
Example #1
Source File: catalog.py From django_blog with MIT License | 6 votes |
def catalog(string): pattern = re.compile(r'<h\d.*</h\d>') match = pattern.findall(string) html = '' for i in range(len(match)): if match[i].startswith('<h2'): if i == 0: html += '<li><a href="#{}">{}</a><ul>'.format(striptags(match[i]), striptags(match[i])) elif i == len(match) - 1: html += '</ul></li><li><a href="#{}">{}</a></li>'.format(striptags(match[i]), striptags(match[i])) else: html += '</ul></li><li><a href="#{}">{}</a><ul>'.format(striptags(match[i]), striptags(match[i])) if match[i].startswith('<h3'): html += '<li><a href="#{}">{}</a></li>'.format(striptags(match[i]), striptags(match[i])) if i == len(match) - 1: html += '</ul>' return html
Example #2
Source File: models.py From securethenews with GNU Affero General Public License v3.0 | 5 votes |
def preview(self): """Returns the first sentence of the post, with HTML tags stripped, for use as a preview blurb.""" body_text = striptags(' '.join([ child.value.source for child in self.body if child.block_type == 'rich_text' ])) sentences = body_text.split('.') return '.'.join(sentences[:1]) + '.'
Example #3
Source File: views.py From janeway with GNU Affero General Public License v3.0 | 5 votes |
def item_title(self, item): return striptags(item.title)
Example #4
Source File: views.py From janeway with GNU Affero General Public License v3.0 | 5 votes |
def item_title(self, item): return striptags(item.title)
Example #5
Source File: forms.py From django-easy-comment with MIT License | 5 votes |
def clean_content(self): """ 检查content字段是否为空 """ value = self.cleaned_data['content'] if striptags(value).replace(' ', '').replace(' ', '') == '' and '<img' not in value: self.add_error('content', '兄dei,评论内容不能为空~') return value
Example #6
Source File: fields.py From bungiesearch with BSD 3-Clause "New" or "Revised" License | 5 votes |
def value(self, obj): val = super(StringField, self).value(obj) if val is None: return None return striptags(val)
Example #7
Source File: forms.py From django_blog with MIT License | 5 votes |
def clean_content(self): value = self.cleaned_data['content'] if striptags(value).replace(' ', '').replace(' ', '') == '' and not '<img' in value: self.add_error('content', '兄dei,评论内容不能为空~') return value
Example #8
Source File: search_helpers.py From es-django-example with Apache License 2.0 | 5 votes |
def highlight_fragments(input): return safe(striptags(' … '.join(input)).replace('[[[', '<em class="highlight">').replace(']]]', '</em>'))
Example #9
Source File: test_striptags.py From djongo with GNU Affero General Public License v3.0 | 5 votes |
def test_strip(self): self.assertEqual( striptags('some <b>html</b> with <script>alert("You smell")</script> disallowed <img /> tags'), 'some html with alert("You smell") disallowed tags', )
Example #10
Source File: test_striptags.py From djongo with GNU Affero General Public License v3.0 | 5 votes |
def test_non_string_input(self): self.assertEqual(striptags(123), '123')
Example #11
Source File: test_striptags.py From djongo with GNU Affero General Public License v3.0 | 5 votes |
def test_strip_lazy_string(self): self.assertEqual( striptags(lazystr('some <b>html</b> with <script>alert("Hello")</script> disallowed <img /> tags')), 'some html with alert("Hello") disallowed tags', )
Example #12
Source File: views.py From django-examples with MIT License | 5 votes |
def get_social_description(self): return truncatewords(striptags(self.object.text), 50)