Remove self links middleware

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
import re

class RemoveSelfLinks:
    def process_response(self, request, response):
        if response.status_code == 200:
            link = request.META['PATH_INFO']
            response.content = \
                re.sub( \
                    r'<a([^>]+)href="%s"([^>]*)>(.*?(?!</a>)[^<]*)</a>' % link, \
                    r'<span \1 \2>\3</span>', \
                    response.content)
        return response

More like this

  1. Page numbers with ... like in Digg by Ciantic 4 years, 1 month ago
  2. True links in the admin list by svetlyak 5 years, 8 months ago
  3. Flash Message Template Tag by rtconner 5 years, 10 months ago
  4. nofollow filter by svetlyak 5 years, 10 months ago
  5. Per-site vary cache on language by fneumann 5 years, 7 months ago

Comments

(Forgotten your password?)