| 118 | |
| 119 | == Debugging == |
| 120 | === Python === |
| 121 | * Use the [DeveloperGuidelines/Eclipse Eclipse IDE] to be able to set breakpoints and inspect expressions. |
| 122 | * WSGI likes print statements to go to {{{sys.stderr}}} not {{{sys.stdout}}}: http://code.google.com/p/modwsgi/wiki/DebuggingTechniques |
| 123 | * use Web2Py shell: http://www.vimeo.com/879939 |
| 124 | * use [http://ipython.scipy.org/moin/ IPython] for interactive exploration (on Windows, install [http://ipython.scipy.org/moin/PyReadline/Intro PyReadline]) |
| 125 | * use [http://groups.google.com/group/web2py/browse_thread/thread/cc13960a5079b2d5# FirePy] to see logging output to Console (to view with Firebug) |
| 126 | * Log to a File: http://groups.google.com/group/web2py/browse_thread/thread/e20d0bd2e542aa14 |
| 127 | * Debug Tools: http://docs.python.org/library/debug.html |
| 128 | * Use [http://stackoverflow.com/questions/2654113/python-how-to-get-the-callers-method-name-in-the-called-method Inspect] to check which function called the one you're troubleshooting: |
| 129 | {{{ |
| 130 | import inspect |
| 131 | curframe = inspect.currentframe() |
| 132 | calframe = inspect.getouterframes(curframe, 2) |
| 133 | current.log.debug("caller name: %s" % calframe[1][3]) |
| 134 | }}} |
| 135 | * Debug SQL Queries: |
| 136 | {{{ |
| 137 | vi gluon/dal.py |
| 138 | class BaseAdapter() |
| 139 | def select(): |
| 140 | def response(sql): |
| 141 | if "searchphrase" in sql: |
| 142 | current.log.debug("Query: %s" % query) |
| 143 | current.log.debug("SQL: %s" % sql) |
| 144 | }}} |
| 145 | * Debug Views: |
| 146 | {{{ |
| 147 | vi gluon/globals.py |
| 148 | def write(self, data, escape=True): |
| 149 | try: |
| 150 | ...All Old Code ... |
| 151 | except Exception, error: |
| 152 | # Put Eclipse breakpoint on the below line |
| 153 | exc_type, exc_value, exc_traceback = sys.exc_info() |
| 154 | pass |
| 155 | }}} |
| 156 | * [http://aymanh.com/python-debugging-techniques Python Debugging Techniques] |
| 157 | * Insert these statements into your code |
| 158 | * Get a Python shell up to explore interactively: {{{import code; code.interact(locals=locals()}}} |
| 159 | * Get a full stack trace: {{{import pdb; pdb.set_trace()}}} |
| 160 | * winpdb: http://groups.google.com/group/web2py/msg/ee46125b7c93fdd4 |
| 161 | * WingIDE: http://www.wingware.com/ |
| 162 | * Using with Web2Py: http://www.wingware.com/doc/howtos/web2py |
| 163 | * [DeveloperGuidelines/Eclipse Eclipse] IDE |
| 164 | * Unicode: |
| 165 | * "Decode early, Unicode everywhere, Encode late": http://farmdev.com/talks/unicode/ |
| 166 | * http://boodebr.org/main/python/all-about-python-and-unicode |
| 167 | * Python Design Patterns: |
| 168 | * http://www.youtube.com/watch?v=Er5K_nR5lDQ |
| 169 | * http://videolectures.net/youtube_martelli_python/ |
| 170 | |
| 171 | === HTML, CSS, and Javascript === |
| 172 | |
| 173 | Each of the major browsers has tools available for viewing HTML page structure and form data, Javascript code, CSS. Some also support Javascript debugging, including setting breakpoints and viewing values in variables. |
| 174 | |
| 175 | * Firefox: Install the [https://addons.mozilla.org/en-US/firefox/addon/firebug/ Firebug] plugin. Start Firebug by clicking the bug icon in the upper right. After the tools open in the lower half of the page, load the page you want to debug. |
| 176 | |
| 177 | * Chrome: Open the [https://developers.google.com/chrome-developer-tools/ Chrome developer tools] with Chrome menu (three bar icon) -> Tools -> Developer tools. |
| 178 | |
| 179 | * Internet Explorer: Open the [http://msdn.microsoft.com/library/ie/bg182326%28v=vs.85%29 IE developer tools] with F12, or Tools (gear icon) -> F12 Developer Tools. Note that you can test behavior of pages under earlier versions of IE by setting your current IE to behave as earlier versions. In the developer tools menu bar, click Browser Mode and select the desired version. |
| 180 | |
| 181 | Other tools that may be of interest: |
| 182 | |
| 183 | * use [http://www.sprymedia.co.uk/article/Visual+Event Visual Event] to see which events are active. |
| 184 | * use Venkman: http://www.mozilla.org/projects/venkman/ |
| 185 | * use Fiddler for compressed files: http://www.yuiblog.com/blog/2008/06/27/fiddler |
| 186 | * http://pastebin.me (allows edits of HTML & previews) |
| 187 | * http://jsfiddle.net (allows edits of JS & previews) |
| 188 | * http://yura.thinkweb2.com/domlint/ |
| 189 | * http://www.jslint.com/lint.html |
| 190 | * IE6 cheatsheet: http://www.virtuosimedia.com/tutorials/ultimate-ie6-cheatsheet-how-to-fix-25-internet-explorer-6-bugs |
| 191 | |
| 192 | == Additional Tips == |
| 193 | ''See:'' DeveloperGuidelines/Tips |