我想分析從具有#hashtag用戶輸入一個字符串,與其他詞太如何從用戶帖子/字符串中提取hashtag?
只是Facebook和Twitter的方式一起打印出來的結果處理吧:)
例如: 用戶帖子
「你好#word,正在學習#python和#django今天」!
我要出去放是: 地獄o #word,今天正在學習#python和#django!
這是多遠我已經走了:
@login_required
@ajax_required
def post(request):
last_feed = request.POST.get('last_feed')
user = request.user
csrf_token = (csrf(request)['csrf_token'])
feed = Feed()
feed.user = user
post = request.POST['post']
lookup_hash_tag = post.strip()
hstg=re.compile(r"#(\w+)")
#print pat.findall(s)
for hashtag in hstg.findall(lookup_hash_tag):
post = "<span><a href='/hastag/?q={}'>{}</a> </span> {}".format(hashtag, hashtag, post.replace('#', '#'))
if len(post) > 0:
feed.post = post[:255]
feed.save()
html = _html_feeds(last_feed, user, csrf_token)
return HttpResponse(html)
你需要對你的問題非常具體,否則你會繼續下臺。 – 16num
嘗試創建自定義過濾器,https://stackoverflow.com/a/2507447/3762142和https://djangosnippets.org/snippets/2072/這是您的出發點 –