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.

To enter a block of code:

  • enter empty line after your previous text
  • paste or type the code
  • select the code and press the button above
Preview: (hide)
piskvorky's avatar
350
piskvorky
asked 13 years ago, updated 13 years ago

Comments

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.

To enter a block of code:

  • enter empty line after your previous text
  • paste or type the code
  • select the code and press the button above
Preview: (hide)
Evgeny's avatar
13.2k
Evgeny
answered 13 years ago
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 (13 years ago)

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 (13 years ago)

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 (13 years ago)

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 (13 years ago)
see more comments