我有一个Django应用程序,我正在添加Django日志对象,我遵循此文档 https://code.osuosl.org/projects/django-object-log/wiki/Usage#Registering-Action-Types
我正在文档中添加日志条目 下面给出了如何在def方法中添加日志的示例,下面是示例:
# 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,我想添加日志调用
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)
该错误可能是什么原因?
答案 0 :(得分:1)
您最有可能在源文件中混合制表符和空格。您可以手动检查,或者像pyflakes这样的工具可以自动检查。
关于您需要调用的寄存器功能的错误:
from object_log.models import LogAction
LogAction.objects.register('MY_EVENT','template.html', build_cache)