views:

303

answers:

5

I've setup Treebeard in Django and everything seems to have gone well. I tried to setup the admin system and I can see my models being presented in the admin interface. However, when I try to add new data using the admin interface, I get the following error in my template. The code still works fine, and I did a check in my DB and the data seems to be inserted properly. However, the view doesn't seem to load properly. Any idea about what is causing this??

The exception am getting is:

Caught an exception while rendering: Failed lookup for key [request] in u'[{\'action_index\': 0, \'block\': , , , , , , ]>}, {\'block\': , , , ]>, , , , , \n \'>, ]>, , ]>, , , , ]>, , , \n \'>, , , , , , , , , ]>, , ]>, \n \'>]>}, {\'cl\': , \'root_path\': None, \'actions_on_bottom\': False, \'title\': u\'Select album to change\', \'has_add_permission\': True, \'media\': , \'is_popup\': False, \'action_form\': , \'actions_on_top\': True, \'app_label\': \'gallery\'}, {\'MEDIA_URL\': \'\'}, {\'LANGUAGES\': ((\'ar\', \'Arabic\'), (\'bn\', \'Bengali\'), (\'bg\', \'Bulgarian\'), (\'ca\', \'Catalan\'), (\'cs\', \'Czech\'), (\'cy\', \'Welsh\'), (\'da\', \'Danish\'), (\'de\', \'German\'), (\'el\', \'Greek\'), (\'en\', \'English\'), (\'es\', \'Spanish\'), (\'et\', \'Estonian\'), (\'es-ar\', \'Argentinean Spanish\'), (\'eu\', \'Basque\'), (\'fa\', \'Persian\'), (\'fi\', \'Finnish\'), (\'fr\', \'French\'), (\'ga\', \'Irish\'), (\'gl\', \'Galician\'), (\'hu\', \'Hungarian\'), (\'he\', \'Hebrew\'), (\'hi\', \'Hindi\'), (\'hr\', \'Croatian\'), (\'is\', \'Icelandic\'), (\'it\', \'Italian\'), (\'ja\', \'Japanese\'), (\'ka\', \'Georgian\'), (\'ko\', \'Korean\'), (\'km\', \'Khmer\'), (\'kn\', \'Kannada\'), (\'lv\', \'Latvian\'), (\'lt\', \'Lithuanian\'), (\'mk\', \'Macedonian\'), (\'nl\', \'Dutch\'), (\'no\', \'Norwegian\'), (\'pl\', \'Polish\'), (\'pt\', \'Portuguese\'), (\'pt-br\', \'Brazilian Portuguese\'), (\'ro\', \'Romanian\'), (\'ru\', \'Russian\'), (\'sk\', \'Slovak\'), (\'sl\', \'Slovenian\'), (\'sr\', \'Serbian\'), (\'sv\', \'Swedish\'), (\'ta\', \'Tamil\'), (\'te\', \'Telugu\'), (\'th\', \'Thai\'), (\'tr\', \'Turkish\'), (\'uk\', \'Ukrainian\'), (\'zh-cn\', \'Simplified Chinese\'), (\'zh-tw\', \'Traditional Chinese\')), \'LANGUAGE_BIDI\': False, \'LANGUAGE_CODE\': \'en-us\'}, {}, {\'perms\': , \'messages\': [], \'user\': }, {}]'

This happens after I hit the save button in Django admin.

This is my admin.py implementation:

class MP_Album_Admin(TreeAdmin):
 pass

admin.site.register(Album,MP_Album_Admin)
A: 

You have to add 'django.core.context_processors.request' to TEMPLATE_CONTEXT_PROCESSORS tuple in settings.py.

ml
Please check my update.. and help me plz..
Sharath
A: 

Great.. that worked.. should have looked at the docs better. But now, my template loading is failing.

My settings.py is this.. TEMPLATE_DIRS = ( # Put strings here, like "/home/html/django_templates" or "C:/www/django/templates". # Always use forward slashes, even on Windows. # Don't forget to use absolute paths, not relative paths. "/Projects/myProj/templates", "/Projects/myProj/treebeard/templates",),

My views.py is this.. def index(request): return render_to_response('index.html')

The template loader postmortem shows me that its not even looking inside "/Projects/myProj/templates" for the template even though its specified in settings.py The index.html file located there.

Sharath
A: 

Maybe you forgot to add 'treebeard' application to INSTALLED_APPS.

My settings.py is similar to default one. I always add PROJECT_PATH = os.path.dirname(os.path.abspath(__ file__)) variable, so my TEMPLATE_DIRS looks like that:

TEMPLATE_DIRS = (
    PROJECT_PATH + '/templates',
)
ml
A: 

I got the same error. I've tried to get TreeAdmin working with Adjacency List and Nested Sets.

Caught an exception while rendering: Failed lookup for key [request] in u'[{\'block\': , , , , , , ]>}, {\'block\': , , , ]>, , , , , \n \'>, ]>, , ]>, , , , ]>, , , \n \'>, , , , , , , , , ]>, , ]>, \n \'>]>}, {\'cl\': , \'root_path\': None, \'actions_on_bottom\': False, \'title\': u\'Select Nested Set Tree Post to change\', \'has_add_permission\': True, \'media\': , \'is_popup\': False, \'action_form\': , \'actions_on_top\': True, \'app_label\': \'nested\'}, {\'MEDIA_URL\': \'\'}, {\'LANGUAGES\': ((\'ar\', \'Arabic\'), (\'bn\', \'Bengali\'), (\'bg\', \'Bulgarian\'), (\'ca\', \'Catalan\'), (\'cs\', \'Czech\'), (\'cy\', \'Welsh\'), (\'da\', \'Danish\'), (\'de\', \'German\'), (\'el\', \'Greek\'), (\'en\', \'English\'), (\'es\', \'Spanish\'), (\'et\', \'Estonian\'), (\'es-ar\', \'Argentinean Spanish\'), (\'eu\', \'Basque\'), (\'fa\', \'Persian\'), (\'fi\', \'Finnish\'), (\'fr\', \'French\'), (\'ga\', \'Irish\'), (\'gl\', \'Galician\'), (\'hu\', \'Hungarian\'), (\'he\', \'Hebrew\'), (\'hi\', \'Hindi\'), (\'hr\', \'Croatian\'), (\'is\', \'Icelandic\'), (\'it\', \'Italian\'), (\'ja\', \'Japanese\'), (\'ka\', \'Georgian\'), (\'ko\', \'Korean\'), (\'km\', \'Khmer\'), (\'kn\', \'Kannada\'), (\'lv\', \'Latvian\'), (\'lt\', \'Lithuanian\'), (\'mk\', \'Macedonian\'), (\'nl\', \'Dutch\'), (\'no\', \'Norwegian\'), (\'pl\', \'Polish\'), (\'pt\', \'Portuguese\'), (\'pt-br\', \'Brazilian Portuguese\'), (\'ro\', \'Romanian\'), (\'ru\', \'Russian\'), (\'sk\', \'Slovak\'), (\'sl\', \'Slovenian\'), (\'sr\', \'Serbian\'), (\'sv\', \'Swedish\'), (\'ta\', \'Tamil\'), (\'te\', \'Telugu\'), (\'th\', \'Thai\'), (\'tr\', \'Turkish\'), (\'uk\', \'Ukrainian\'), (\'zh-cn\', \'Simplified Chinese\'), (\'zh-tw\', \'Traditional Chinese\')), \'LANGUAGE_BIDI\': False, \'LANGUAGE_CODE\': \'en-us\'}, {}, {\'perms\': , \'messages\': [], \'user\': }, {}]'

Model for Nested Sets:

from django.db import models
from treebeard.ns_tree import NS_Node

class Category(NS_Node):
    name  = models.CharField(max_length=255)

    def get_absolute_url(self):
        return ('node-view', ('ns', str(self.id),))

    def __unicode__(self):
        return u'NS_Post %d: %s' % (self.id, self.name)

class Meta:
    verbose_name = 'Nested Set Tree Post'

    # when adding a custom Meta class to a NS model, the ordering must be
    # set again
    ordering = ['tree_id', 'lft']

Model for Adjacency List:

from django.db import models
from treebeard.al_tree import AL_Node

class Category(AL_Node):
    name  = models.CharField(max_length=255)
    parent = models.ForeignKey('self',related_name='children_set',null=True,blank=True,db_index=True)
    node_order_by = ['name']

    @models.permalink
    def get_absolute_url(self):
       return ('node-view', ('al', str(self.id),))

    def __unicode__(self):
        return self.name

I tried to fix it with

TEMPLATE_CONTEXT_PROCESSORS = 'django.core.context_processors.request'

in settings.py like ml suggested on Mar 27 at 23:16. Now I've the error

Exception Type:     ValueError
Exception Value:    Empty module name
surfi
+1  A: 

I found a solution. It's not sufficient adding 'django.core.context_processors.request' to TEMPLATE_CONTEXT_PROCESSORS tuple in settings.py.

I added also

"django.core.context_processors.auth",
"django.core.context_processors.debug",
"django.core.context_processors.i18n",
"django.core.context_processors.media"

and now it works.

surfi