Ask Your Question
0

Introduce Custom Tags

asked 2014-01-12 09:01:07 -0500

SocialQA gravatar image

updated 2014-01-12 09:01:56 -0500

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.

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

answered 2014-01-12 11:08:15 -0500

Evgeny gravatar image

We are using Jinja2 templates, therefore please refer to their documentation. Also, in Jinja2 it's easier to write custom template filters rather than template tags, perhaps you could achieve your goal that way.

edit flag offensive delete link more

Comments

but if I want to do this was it should work right? I don't want to deal with Jinja as want to avoid as much as possible.

SocialQA gravatar imageSocialQA ( 2014-01-12 14:50:22 -0500 )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

1 follower

Stats

Asked: 2014-01-12 09:01:07 -0500

Seen: 115 times

Last updated: Jan 12 '14