Changes between Version 1 and Version 2 of SimplePrintAppForDebugging
- Timestamp:
- Dec 21, 2006, 7:05:54 PM (18 years ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
SimplePrintAppForDebugging
v1 v2 2 2 3 3 Below, I describe a simple app that writes those messages to a file and then displays those messages in a webpage. To start out, create a new app in your project. Adjust the permissions on the app folder so that your view can write to the folder. Next, paste the following code into the views.py file in your app. 4 5 4 6 5 {{{ … … 40 39 by deleting the file. 41 40 ''' 42 43 from django.http import HttpResponse44 41 from django.shortcuts import render_to_response 45 42 from django.conf import settings … … 53 50 54 51 def write(message): 55 fname=get_filename() 56 try: 57 fp=file(fname,'a+') 58 fp.write(str(datetime.now())+': '+message) 59 fp.close() 60 except: 61 return HTTPHttpResponse( 62 "Error in DEBUG_MESSAGES: could not write to file: %s\n"% fname+ 63 "Make sure you have write privledges to this folder.") 52 fp=file(get_filename(),'a+') 53 fp.write(str(datetime.now())+': '+message) 54 fp.close() 64 55 65 56 def get_filename(): … … 97 88 }}} 98 89 99 Create a subfolder called templates. In that folder create a file called "debug_messages.html" and paste the following code into it:90 Create a subfolder in your app called templates. In that folder create a file called "debug_messages.html" and paste the following code into it: 100 91 101 92 … … 142 133 }}} 143 134 135 "Your message" should be a string. If you want each message to start on a newline, then make sure the string ends it a \n. 136 144 137 To view the messages, point your browswer to the url: 145 138 146 139 root/debug_messages/ 147 140 148 141 Happy debugging!