packages - django-likes: setup and error -
being new django trying implement first package, django-likes, , keep running error below. documentation , project code listed below. advice , insight appreciated.
note: model being utilized modelform
documentation: https://crate.io/packages/django-likes/
error:
exception type: keyerror exception value: 'request' exception location: /home/alxmrph/webapps/dearmusic/lib/python2.7/django/template/context.py in __getitem__, line 57 python executable: /usr/local/bin/python
settings.py:
template_context_processors =( 'django.contrib.auth.context_processors.auth', 'django.core.context_processors.debug', 'django.core.context_processors.i18n', 'django.core.context_processors.media', 'django.core.context_processors.static', 'django.core.context_processors.tz', 'django.contrib.messages.context_processors.messages', 'django.core.context_processors.request', ) middleware_classes = ( 'django.middleware.common.commonmiddleware', 'django.contrib.sessions.middleware.sessionmiddleware', 'django.middleware.csrf.csrfviewmiddleware', 'django.contrib.auth.middleware.authenticationmiddleware', 'django.contrib.messages.middleware.messagemiddleware', 'secretballot.middleware.secretballotipmiddleware', 'secretballot.middleware.secretballotuseripuseragentmiddleware', 'likes.middleware.secretballotuseripuseragentmiddleware', ) installed_apps = ( ... 'secretballot', 'likes', )
models.py:
from django.db import models import secretballot ... class letter(models.model): ... def __unicode__(self): return self.name secretballot.enable_voting_on(letter)
views.py:
def submission(request, pk): submission = get_object_or_404(letter, pk=int(pk)) pk = int(pk) return render_to_response('post.html', {'submission':submission}, context_instance=requestcontext(request))
post.html:
{% load likes_inclusion_tags %} <some html> {% likes submission %} <some html>
traceback
environment: request method: get` django version: 1.5 python version: 2.7.5 installed applications: ('django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.sites', 'django.contrib.messages', 'django.contrib.staticfiles', 'django.contrib.admin', 'django.contrib.admindocs', 'taggit', 'letter', 'south', 'django_social_share', 'secretballot', 'likes') installed middleware: ('django.middleware.common.commonmiddleware', 'django.contrib.sessions.middleware.sessionmiddleware', 'django.middleware.csrf.csrfviewmiddleware', 'django.contrib.auth.middleware.authenticationmiddleware', 'django.contrib.messages.middleware.messagemiddleware', 'secretballot.middleware.secretballotipuseragentmiddleware', 'likes.middleware.secretballotuseripuseragentmiddleware') template error: in template /home/alxmrph/webapps/dearmusic/dearmusic/letter/templates/post.html, error @ line 15 request 5 : <!doctype html public "-//w3c//dtd html 4.01//en" "http://www.w3.org/tr/html4/strict.dtd"> 6 : <html> 7 : <head> 8 : <link href="/static/css/letter.css" rel="stylesheet" type="text/css"> 9 : <link href='http://fonts.googleapis.com/css?family=open+sans:300italic,400italic,600italic,700italic,800italic,400,300,600,700,800' rel='stylesheet' type='text/css'> 10 : 11 : </head> 12 : 13 : <body> 14 : <title class="title">music morphs - story of {{ submission.name }}: {{ submission.letter_summary }}</title> 15 : {% likes submission %} 16 : <header class="header"> 17 : <div class="wrapper_header"> 18 : <div class="title"> 19 : <img src="/static/images/logo.png"> 20 : </div> 21 : <nav><ul> 22 : <li><a href="#">write story</a></li> 23 : </ul></nav> 24 : </div> 25 : </header> traceback: file "/home/alxmrph/webapps/dearmusic/lib/python2.7/django/core/handlers/base.py" in get_response 115. response = callback(request, *callback_args, **callback_kwargs) file "/home/alxmrph/webapps/dearmusic/dearmusic/letter/views.py" in submission 13. return render_to_response('post.html', file "/home/alxmrph/webapps/dearmusic/lib/python2.7/django/shortcuts/__init__.py" in render_to_response 29. return httpresponse(loader.render_to_string(*args, **kwargs), **httpresponse_kwargs) file "/home/alxmrph/webapps/dearmusic/lib/python2.7/django/template/loader.py" in render_to_string 172. return t.render(context(dictionary)) file "/home/alxmrph/webapps/dearmusic/lib/python2.7/django/template/base.py" in render 140. return self._render(context) file "/home/alxmrph/webapps/dearmusic/lib/python2.7/django/template/base.py" in _render 134. return self.nodelist.render(context) file "/home/alxmrph/webapps/dearmusic/lib/python2.7/django/template/base.py" in render 830. bit = self.render_node(node, context) file "/home/alxmrph/webapps/dearmusic/lib/python2.7/django/template/debug.py" in render_node 74. return node.render(context) file "/home/alxmrph/webapps/dearmusic/lib/python2.7/django/template/base.py" in render 1185. _dict = func(*resolved_args, **resolved_kwargs) file "/home/alxmrph/lib/python2.7/django_likes-0.0.11-py2.7.egg/likes/templatetags/likes_inclusion_tags.py" in likes 14. request = context['request'] file "/home/alxmrph/webapps/dearmusic/lib/python2.7/django/template/context.py" in __getitem__ 57. raise keyerror(key) exception type: keyerror @ /letter/testing/15/what/ exception value: 'request'`
looks running django-likes
on django 1.5 in usage of takes_context
parameter of inclusion_tag
has changed
note when you’re using takes_context=true, there’s no need pass arguments template tag. automatically gets access context.
and likes
template tag code is
@register.inclusion_tag('likes/inclusion_tags/likes_extender.html', takes_context=true) def likes(context, obj, template=none): if template none: template = 'likes/inclusion_tags/likes.html' request = context['request'] import_js = false if not hasattr(request, '_django_likes_js_imported'): setattr(request, '_django_likes_js_imported', 1) import_js = true context.update({ 'template': template, 'content_obj': obj, 'likes_enabled': likes_enabled(obj, request), 'can_vote': can_vote(obj, request.user, request), 'content_type': "-".join((obj._meta.app_label, obj._meta.module_name)), 'import_js': import_js }) return context
which ok in django 1.4
update
the easiest solution downgrading django. if want stay django 1.5 you'll have modify
def likes(context, obj, template=none):
to , lern obj
context
def likes(context): obj = context['likes_object'] ...
in template can pass variable with
tag
{% likes_object = submission %} {% likes %} {% endwith %}
Comments
Post a Comment