Django 'urlize' lines form text just like twitter

heyy there

I want to parse the text, I will call it "post" and "urlize" some lines if they contain a specific character in a certain position.

my "pseudo-code" will look like this:

 def urlize(post)
      for string in post
      if string icontains ('#')
      url=(r'^searchn/$',
                    searchn,
                    name='news_searchn'),
     then apply url to the string
     return urlize(post)

I want the function to return me a message with urlized strings where necessary (just like twitter).

I don’t understand: how can I parse the text and search for specific lines? is it ok to make a function, especially for "urlizing" some lines? The function should return the entire post, regardless of whether it has such lines. is there any other way that django offers? Thanks you

+3
1

-, , ( "urlized" ).

urlize,

{{ value|urlize }}

.

, .

EDIT:
# , :

import re
a = "hello #world. foo #bar! #foo_bar"
re.findall("#(\w+)",a)

>> ['world', 'bar', 'foo_bar']
+4

Source: https://habr.com/ru/post/1746762/


All Articles