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. @reply links in Twitter messages by ryanberg 3 years, 10 months ago
  2. Page numbers with ... like in Digg by Ciantic 3 years, 1 month ago
  3. True links in the admin list by svetlyak 4 years, 8 months ago
  4. YUI Loader as Django middleware by akaihola 4 years, 1 month ago
  5. More information about users and groups in user admin by ramusus 2 years, 10 months ago

Comments

(Forgotten your password?)