Code

Changes between Version 1 and Version 2 of SimplePrintAppForDebugging


Ignore:
Timestamp:
12/21/06 17:05:54 (7 years ago)
Author:
Chuck Martin <cwurld@…>
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • SimplePrintAppForDebugging

    v1 v2  
    22 
    33Below, 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  
    54 
    65{{{ 
     
    4039by deleting the file. 
    4140''' 
    42  
    43 from django.http import HttpResponse 
    4441from django.shortcuts import render_to_response 
    4542from django.conf import settings 
     
    5350 
    5451def 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() 
    6455 
    6556def get_filename(): 
     
    9788}}} 
    9889 
    99 Create a subfolder called templates. In that folder create a file called "debug_messages.html" and paste the following code into it: 
     90Create a subfolder in your app called templates. In that folder create a file called "debug_messages.html" and paste the following code into it: 
    10091 
    10192 
     
    142133}}} 
    143134 
     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 
    144137To view the messages, point your browswer to the url: 
    145138 
    146139root/debug_messages/ 
    147140 
    148  
     141Happy debugging!