I am working on a project which is based on open-source. It's call askbot. I wanted to add a/b testing to it and after doing some research I found out django-lean. I am not an expert in django but I manage to bring the strip down version of the django-lean to my version of askbot-dlevel. I used the blog post. But my problem is that I am getting following error:
TemplateSyntaxError at /questions/
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'.
Just to give more information how I incorporate django-lean: As the blog-post mention I only use the experiments module:
I added experiments folder from django-lean inside askbot folder and expose it as another install-app using settings file. So now it looks like another application.
I copied experiments.py and smartif.py to askbot-dlevel/templatetags because thats the right thing to do based on he django documentation:
In askbot-dlevel there is a utils folder and in that there is decorators.py, I added the following:
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
Now as mentioned in the blog-post I added following to my view:
@csrf.csrf_protect
@decorators.set_experiment_user
def ask_widget(request, widget_id):
def post_question(data, request):
thread = models.Thread.objects.create_new(**data)
question = thread._question_post()
request.session['widget_question_url'] = question.get_absolute_url()
return question
widget = get_object_or_404(models.AskWidget, id=widget_id)
...
and in my template just as the blog post mentioned I did the following:
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 %}
as this point as the blog post mention things should work. Using the admin console I have created and experiment and the name of the experiment is top_contributors. And if things run all users would be in the experiment. But I am getting above mention error which tells me template tags have not been registered.
askbot-dlevel project uses jinja2 (I think) but looks like blog-post has written its template code in regular django template mode. Could this be an issue? How can I convert this to jinja if thats the case. If not what am I missing here?
To best of my knowledge I tried to convert what blog-post written into jinja2:
{% if experiments.experiment('top_contributors') %}
{% if contributors and settings.SIDEBAR_MAIN_SHOW_AVATARS %}
{% include "widgets/contributors.html" %}
{% endif %}
{% endif %}
After this I get following error:
UndefinedError at /questions/
'experiments' is undefined
Request Method: GET
Request URL: http://localhost:8001/questions/
Django Version: 1.4.10
Exception Type: UndefinedError
Exception Value:
'experiments' is undefined
Exception Location: ..python2.7/site-packages/Jinja2-2.7.1-py2.7.egg/jinja2/environment.py in getattr, line 397
Python Executable: ../ABFrameWork/bin/python
django-lean
app? What if you removeexperiments.py
andsmartif.py
from your templatetags package? Have you followed the installation procedure described here?