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: also I copied content of the templates folder in the django-lean to askbot-dlevel project's templates folder. So here is how the project looks like:
askbot-dlevel
|__experiments
|__OtherApps
templates
|__experiments
|__other_templates
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
This is a slight modification respect to what the blog-post has mentioned but the logic is still the same. At the point blog-post advise to add it to the views so I added to a view in the askbot-dlevel project:
@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)
...
after this I added the necessary code to the template file which would add all incoming users to the current experiment that is live on the. Now askbot-dlevel uses jinja2. I but I first tried as the blog post mention because I really don't have a good idea of jinja.
So in sidebar.html of the adkbot-dlevel I added 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 %}
{% endexperiment %}
But that gave me the error that I put at the start of this post. As the blog post mention things should work. Using the admin console I have created an 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.
So I tried my best to convert this to jinja format and tried the following:
{% if experiments.experiment('top_contributors') %}
{% if contributors and settings.SIDEBAR_MAIN_SHOW_AVATARS %}
{% include "widgets/contributors.html" %}
{% endif %}
{% endif %}
But that gave me 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
Hopefully someone can help on solving this problem.
Thank You,
--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/f3b009ea-a66e-4888-83db-8b8bba4e4a9a%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.