1
林有一個Django應用程序和Im加入Django的日誌反對,林本文檔 https://code.osuosl.org/projects/django-object-log/wiki/Usage#Registering-Action-Types意外的縮進錯誤對象
我在這給文檔 中添加日誌條目的部分是以下如何在一個高清方法添加日誌下面的示例中,這裏是例子:
# store log_action for faster access
log = LogItem.objects.log_action
def my_view(request, pk):
""" example view that retrieves an object by its pk """
obj = SomeModel.objects.get(pk=pk)
log('MY_EVENT', request.user, obj)
tasks.py是在我的應用程序中的觀點,這是一個高清,我想添加日誌呼叫
def edit_task(request, task_id):
t = get_object_or_404(Task, pk=task_id)
t.category = request.POST['cat_dd']
t.subcategory = request.POST['subcat_dd']
t.name = request.POST['task_name']
t.description = request.POST['task_desc']
t.country = request.POST['country_dd']
t.city = request.POST['task_city']
t.address = request.POST['task_address']
t.status = request.POST['status_dd']
log('MY_EVENT', request.user, t)
if (employer_id == NULL or getcategory == "Please select a category" or getsubcategory == "Please select a subcategory" or getname == "" or getdesc == "Write a short description about your task.." or getcountry == "(please select a country)" or getcity == "" or getaddress == "" or getstatus == ""):
return render_to_response('editTask.html',RequestContext(request))
else:
t = Task.objects.create(employer = employer_id, category = getcategory, subcategory = getsubcategory, name = getname, description = getdesc, country = getcountry, city = getcity, address = getaddress, status = getstatus, contractor = NULL)
t.save()
return render_to_response('task.html',RequestContext(request))
在前面的代碼中加入這一行log('MY_EVENT', request.user, t)
後,我得到了一個錯誤
我得到一個錯誤unexpected indent (tasks.py, line 58)
,這可能是該錯誤的原因?
你有雙重檢查空間/製表縮進? – 2012-04-23 20:28:17
是第58行'log('MY_EVENT',request.user,t)'?如果是這樣,你可以檢查標籤,或其他不可見的縮進? (有時會出現複製和粘貼的問題) – Levon 2012-04-23 20:28:23
沒有看到任何縮進錯誤,但在Python中沒有「NULL」這樣的東西。 – 2012-04-23 20:36:16