First time here? Check out the FAQ!
2

`'settings' is undefined` in custom template?

I see the askbot templates use constructs like {% if settings.BLABLA %}.

From what I understand, the settings var should always be present, from askbot.context.application_settings, right?

But when I try to use {% if settings.XYZ %} in my own skin widgets, I get

Exception Type: UndefinedError
Exception Value:   'settings' is undefined

How can that be? I would post more info but don't know what could be relevant to this.

piskvorky's avatar
350
piskvorky
asked 2012-02-18 10:53:36 -0500, updated 2012-02-18 10:56:46 -0500
edit flag offensive 0 remove flag close merge delete

Comments

add a comment see more comments

1 Answer

1

I did disable settings injection into non-askbot views to reduce impact of askbot on other apps. Just add template settings directly in your view. If you are not comfortable with handpicking the settings for the templates - copy a snippet from /askbot/context.py to load all the livesettings at once.

IMO it was a poor idea to put settings into the template context processor, because it slows down everything in the django project even apps that have nothing to do with askbot. I am thinking of completely moving to manually populating the template context in each view.

We are now focusing on improving performance of the app now, so cutting that fat where possible.

Evgeny's avatar
13.2k
Evgeny
answered 2012-02-18 11:06:20 -0500
edit flag offensive 0 remove flag delete link

Comments

That makes sense in the future, but how did you disable it now? I still see askbot.context.application_settings in the context processors (using askbot from jan 11).

piskvorky's avatar piskvorky (2012-02-18 12:01:34 -0500) edit

hah, yes disabling only works if askbot is installed on a sub-url like /forum. For you all you are missing is probably the RequestContext for the view, no?

Evgeny's avatar Evgeny (2012-02-18 12:07:43 -0500) edit

No, actually I found the problem was with macros -- the context is not being passed. For now I replaced the macros indirection with a simple direct {% include %}, I'll have to read more about how macros work later.

piskvorky's avatar piskvorky (2012-02-18 12:34:02 -0500) edit

In macros you only see the variables that you give explicitly. They do not receive the template context, so this is an expected behavior.

Evgeny's avatar Evgeny (2012-02-19 11:32:30 -0500) edit
add a comment see more comments