2015-04-22 68 views

回答

1

在谷歌電子表格中存儲崩潰報告的方法是使用gspread。例如,讓我們做一個函數,將崩潰報告存儲到電子表格。在此之前,製作電子表格並獲取它的網址。

def store_crash_report(request, report): 
    gc = gspread.login('[email protected]', 'password') 
    sht=gc.open_by_url('https://docs.google.com/spreadsheets/d/121...jRRSg') 
    #url of spread sheet 
    worksheet = sht.get_worksheet(0) 
    x_forwarded_for = request.META.get('HTTP_X_FORWARDED_FOR') 
    if x_forwarded_for: 
     ip = x_forwarded_for.split(',')[0] 
    else: 
     ip = request.META.get('REMOTE_ADDR') 
    date_time = str(datetime.now()) 
    worksheet.insert_row([date_time, ip, report]) 

,並用它查看這樣的:

def view(request): 
    try: 
    ... 
    exception Exception as e: 
     store_crash_report(request, e)