Login

"Open file in Textmate"-support in werkzeug debugger browser view

Author:
grandfatha
Posted:
February 21, 2012
Language:
Python
Version:
1.3
Score:
1 (after 1 ratings)

1) Install django-extensions (requires werkzeug) 2) Paste snippet into settings.py 3) manage.py runserver_plus

Now you should be able to open files in textmate by clicking the file links in the werkzeug error pages. It will also take you to the correct line number and highlight files that are in your project directory in a different color.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
PROJECT_DIR = os.path.abspath(os.path.dirname(__file__))

try:
  from werkzeug.debug import tbtools
  from werkzeug.utils import escape
  tbtools.FRAME_HTML = u'''\
  <div class="frame" id="frame-%(id)d">
    <h4>File <a style="color:%(projectfile)s;" href="txmt://open/?url=file://%(filename)s&line=%(lineno)s" class="filename">%(filename)s</a>,
        line <em class="line">%(lineno)s</em>,
        in <code class="function">%(function_name)s</code></h4>
    <pre>%(current_line)s</pre>
  </div>
  '''
  
  def myrender(self):
    return tbtools.FRAME_HTML % {
      'id':       self.id,
      'projectfile':    'firebrick' if self.filename.find(PROJECT_DIR) == 0 else 'inherit',
      'filename':     escape(self.filename),
      'lineno':     self.lineno,
      'function_name':  escape(self.function_name),
      'current_line':   escape(self.current_line.strip())
    }
  
  tbtools.Frame.render = myrender
  
except ImportError:
  pass

More like this

  1. Month / Year SelectDateWidget based on django SelectDateWidget by pierreben 3 months ago
  2. Python Django CRUD Example Tutorial by tuts_station 3 months, 2 weeks ago
  3. Browser-native date input field by kytta 5 months ago
  4. Generate and render HTML Table by LLyaudet 5 months, 1 week ago
  5. My firs Snippets by GutemaG 5 months, 1 week ago

Comments

Please login first before commenting.