First time here? Check out the FAQ!

Revision history  [back]

Introduce Custom Tags

I see the templatetags folder inside askbot. I have been adding all the new apps that I build on top of askbot under askbot folder.

I have my main application askbot and inside that I have experiments folder as another application.

I used askbot's utils module to introduce the tags of my application. I used the decorators.py.

def set_experiment_user(view_func):
    '''Decorator for setting the WebUser for use with ab split testing assumes
    first argument is the request object'''
    @functools.wraps(view_func)
    def decorator(request, *args, **kwargs):
        WebUser(request).confirm_human()
        return view_func(request, *args, **kwargs)
    return decorator

Then in my view

@decorators.set_experiment_user
def ask_widget(request, widget_id):

and in the template, I have done the following:

{% import "macros.html" as macros %}

{% load experiments %}
{% experiment experiment_name top_contributors %}
{% if contributors and settings.SIDEBAR_MAIN_SHOW_AVATARS %}
    {% include "widgets/contributors.html" %}
{% endif %}
{% endexperiments %}

But I get the following error: But I get the following error:

Encountered unknown tag 'experiment'.
Request Method: GET
Request URL:    http://localhost:8001/questions/
Django Version:  1.4.10
Exception Type:  TemplateSyntaxError
Exception Value:    
Encountered unknown tag 'experiment'.
Exception Location: ../askbot/templates/main_page/sidebar.html in template, line 4

this means that it doesn't understand the "experiment" template tag, I read the following url since I have 'django.core.context_processors.request', in settings.py I didn't think i have to do anything to make sure custom templates to be registered.

https://docs.djangoproject.com/en/1.4/howto/custom-template-tags/

It would be a great help if you could provide any insight on this.

I also have utils.py in my experiment module should I be my set_experiment into that instead of askbot's utils.

Introduce Custom Tags

I see the templatetags folder inside askbot. I have been adding all the new apps that I build on top of askbot under askbot folder.

I have my main application askbot and inside that I have experiments folder as another application.

I used askbot's utils module to introduce the tags of my application. I used the decorators.py.

def set_experiment_user(view_func):
    '''Decorator for setting the WebUser for use with ab split testing assumes
    first argument is the request object'''
    @functools.wraps(view_func)
    def decorator(request, *args, **kwargs):
        WebUser(request).confirm_human()
        return view_func(request, *args, **kwargs)
    return decorator

Then in my view

@decorators.set_experiment_user
def ask_widget(request, widget_id):

and in the template, I have done the following:

{% import "macros.html" as macros %}

{% load experiments %}
{% experiment experiment_name top_contributors %}
{% if contributors and settings.SIDEBAR_MAIN_SHOW_AVATARS %}
    {% include "widgets/contributors.html" %}
{% endif %}
{% endexperiments %}

But I get the following error: But I get the following error:

Encountered unknown tag 'experiment'.
Request Method: GET
Request URL:    http://localhost:8001/questions/
Django Version:  1.4.10
Exception Type:  TemplateSyntaxError
Exception Value:    
Encountered unknown tag 'experiment'.
Exception Location: ../askbot/templates/main_page/sidebar.html in template, line 4

this means that it doesn't understand the "experiment" template tag, I read the following url since I have 'django.core.context_processors.request', in settings.py I didn't think i have to do anything to make sure custom templates to be registered.

https://docs.djangoproject.com/en/1.4/howto/custom-template-tags/

It would be a great help if you could provide any insight on this.

I also have utils.py in my experiment module should I be my set_experiment into that instead of askbot's utils.