First time here? Check out the FAQ!

Access settings attribute from template

For example, in user_navigation.html template we have following code:

if settings.KARMA_MODE != 'hidden' and settings.BADGES_MODE != 'hidden'

I want to understand how this is been done, lets say I want to introduce a boolean value in the, how do I access that from my template similar to above technique.

SocialQA's avatar
asked 2013-06-04 13:27:57 -0500
edit flag offensive 0 remove flag close merge delete


add a comment see more comments

1 Answer


If you would like to introduce those values via, then use the convention of the overrides by the livesettings app. Those settings are not the same as uppercased local variables inside the file.

    1: {
        'DB': True,
        'SETTINGS': {
                'KARMA_MODE': 'private',
                'BADGES_MODE': 'hidden'

Where number 1 is site id. Key 'KARMA_AND_BADGE_VISIBILITY' is a section of livesettings - you can see that in the various askbot/conf/*.py files.

In general, I would say this is for the users who do not mind to get their hands on the code. Otherwise it is possible to change them via the /settings/ url.

We might in the future move away from the livesettings app as it has some limitations, and in that case the custom settings specified via the overrides will need to be migrated to the new, hopefully simpler format.

Evgeny's avatar
answered 2013-06-04 13:38:29 -0500
edit flag offensive 0 remove flag delete link


When I search for KARMA_AND_BADGE_VISIBILITY I found by that doesn't look like what you have put in the answer.

SocialQA's avatar SocialQA (2013-06-04 13:57:39 -0500) edit

Yes - open that file and may be it will help you - there inside section with that name is defined. Like I said this is part of the livesettings app which has own conventions of dealing with the settings.

Evgeny's avatar Evgeny (2013-06-04 14:07:07 -0500) edit

You have an index with an integer and curly braces where as in this file it has name KARMA_AND_BADGE_VISIBILITY then settings.register with ( ) braces.

SocialQA's avatar SocialQA (2013-06-04 14:12:56 -0500) edit

That's just Python code. The settings are defined via the function calls and the LIVESETTINGS_OPTIONS is just nested dictionary representing the static overridden values. Once you override them in the you can't change them via the /settings/ url. The 1: { 'DB': True... part - consider that a preamble to the actual settings. The value of 'SETTINGS' is actually what you want to be editing. We have not made effort to make this part user friendly yet, sorry.

Evgeny's avatar Evgeny (2013-06-04 14:19:16 -0500) edit

If I understood correctly what you put in your answer is something that goes into if thats the case similarly karama_and_badge should have a attribute in I think i am super confused... wonder if you can show a simple end to end example. Thanks. May be then I can take an approach to clean it up and do an upstream.

SocialQA's avatar SocialQA (2013-06-04 14:30:33 -0500) edit
add a comment see more comments