Friday, 15 July 2011

Django: "Error importing request processor module" using custom processor -


I have implemented my own reference processor and I'm trying to configure it properly in the settings of the demo:

but I found the following error:

Request to import the request processor module Error Com.mysite.apps.myapp.processors.MyProcessor.MyProcessor: "A module named" My Processor "

My processor is a stable class that is a static method" < Code> process "(I love the ops and I use classes and package architecture in my project). It turns out and spelled correctly ... So what's wrong?

Update:

A simple " process " function (" com.mysite.apps.myapp.processors .MyProcessor.process ") This works ... but I'm not satisfied ... how does Django load these processors? I use a package / class everywhere in my app (model, test, scene ...) and it usually works ... what's the difference here? Since the dynamic nature of Python, a path like " com.mysite.apps.myapp.processors.MyProcessor.MyProcessor " should be independently resolved by a class or a standard "subdomain" ... don 'do you agree?

Django does not know what is. is a sub-package symbol or a variable within that package Then foo.bar.baz.quux has been given to believe that foo , bar , baz all There are packages, and that quux (the final value is the meaning) that is a feature of that module.

TEMPLATE_CONTEXT_PROCESSORS has finally been imported by the value django.template. Context.get_standard_processors ().

This is the relevant bit of code in that function:

  i = path.rfind ('.') Module, Attr = path [: i], path [i + 1:]   

So you can not access nested values ​​within the module. This is clearly not recorded anywhere, which I can see. If you really want to use a static method, then I can see that the only option is:

  class MyProcessor (object): @staticmethod def process (request): # whatever ... process = myProcessor .process   

and then your TEMPLATE_CONTEXT_PROCESSORS "com.mysite.apps.myapp.processors.MyProcessor.process" < / Code>

No comments:

Post a Comment