Ask Your Question
2

`'settings' is undefined` in custom template?

asked 2012-02-18 10:53:36 -0600

piskvorky gravatar image

updated 2012-02-18 10:56:46 -0600

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.

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
1

answered 2012-02-18 11:06:20 -0600

Evgeny gravatar image

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.

edit flag offensive delete link more

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 gravatar imagepiskvorky ( 2012-02-18 12:01:34 -0600 )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 gravatar imageEvgeny ( 2012-02-18 12:07:43 -0600 )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 gravatar imagepiskvorky ( 2012-02-18 12:34:02 -0600 )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 gravatar imageEvgeny ( 2012-02-19 11:32:30 -0600 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

Stats

Asked: 2012-02-18 10:53:36 -0600

Seen: 412 times

Last updated: Feb 18 '12