Django对象日志错误:未定义名称“寄存器”

时间:2012-04-23 21:15:46

标签: python django

我有一个Django应用程序,我正在添加Django日志对象,我遵循此文档https://code.osuosl.org/projects/django-object-log/wiki/Usage#Registering-Action-Types

我在文档中(自动缓存数据)的一部分,这是一个如何添加构建cashe和注册的示例:

def build_cache(user, obj1, obj2, obj3, data):
     return {'foo':obj.foo}

 register('MY_EVENT', 'template.html', build_cache)

 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) 

现在我的代码在添加上述部分时看起来像这样:

from models import *
from django.template import Context, loader, RequestContext
from django.shortcuts import render_to_response , get_object_or_404
from django.http import HttpResponseRedirect, HttpResponse, Http404
from django.core.urlresolvers import reverse
from django.shortcuts import redirect
from django.views.decorators.csrf import csrf_protect
from django.core.mail import EmailMessage
#from django.contrib.formtools.tests.wizard.forms import request

from object_log.models import LogAction
from object_log.models import LogItem

register('MY_EVENT', 'template.html', build_cache)  

def build_cache(user, obj1, obj2, obj3, data):
     return {'foo':obj.foo}



LogAction.objects.register('MY_EVENT','path/to/my/template.html')
LogAction.objects.register('MY_EVENT','path/to/my/template.html')

 # store log_action for faster access
log = LogItem.objects.log_action



def create_task(request):
    #Employer.objects.filter(pk=request.session[user_id])
    employer_id = request.user.id #Take the employer in the current session

    getcategory = request.POST['cat_dd']
    getsubcategory = request.POST['subcat_dd']
    getname = request.POST['task_name']
    getdesc = request.POST['task_desc']
    getcountry = request.POST['country_dd']
    getcity = request.POST['task_city']
    getaddress = request.POST['task_address']
    getstatus = request.POST['status_dd']
    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('createTask.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))

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,data={'foo':obj.foo})

    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()
        #log('MY_EVENT', request.user, obj, data={'foo':obj.foo}) 
        return render_to_response('task.html',RequestContext(request))

但我收到错误名称'register' is not defined

是否有任何解决方案?

2 个答案:

答案 0 :(得分:0)

尝试:

LogAction.objects.register('MY_EVENT', 'template.html', build_cache)

而不是:

register('MY_EVENT', 'template.html', build_cache)  

答案 1 :(得分:0)

如果我们使用 fn main() { { let x = 10; } println!("{}", x); // x is no longer accessible here. } 错误将成为 std::move