Weird error message with django-ratings - django

I'm getting a strange error message with [django-ratings][1]. The following is in my urls.py:
url(r'^rate/(?P<object_id>\d+)/(?P<score>\d+)/', AddRatingFromModel(),{
'app_label': 'spiceapp',
'model': 'spice',
'field_name': 'rating',
}),
If I navigate to this page: /spiceapp/rate/1/2, I get the following error:
Caught AttributeError while rendering: 'AddRatingFromModel' object has no attribute 'name'
What would cause this to happen?
Environment:
Request Method: GET
Request URL: http://localhost:8000/spiceapp/rate/1/2/
Django Version: 1.3.1
Python Version: 2.7.2
Installed Applications:
['django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.messages',
'django.contrib.humanize',
'django.contrib.markup',
'mptt',
'treenav',
'djangoratings',
'django.contrib.databrowse',
'pinax.templatetags',
'django_facebook',
'aiteo',
'haystack',
'notification',
'staticfiles',
'debug_toolbar',
'mailer',
'uni_form',
'crispy_forms',
'django_openid',
'ajax_validation',
'timezones',
'emailconfirmation',
'announcements',
'pagination',
'friends',
'messages',
'oembed',
'groups',
'threadedcomments',
'wakawaka',
'swaps',
'tagging',
'bookmarks',
'photologue',
'avatar',
'flag',
'microblogging',
'locations',
'django_sorting',
'tagging_ext',
'smuggler',
'voting',
'pinax.apps.signup_codes',
'pinax.apps.analytics',
'pinax.apps.blog',
'pinax.apps.tribes',
'pinax.apps.photos',
'pinax.apps.topics',
'pinax.apps.threadedcomments_extras',
'about',
'account',
'waitinglist',
'spiceapp',
'bbauth',
'profiles']
Installed Middleware:
['django.middleware.common.CommonMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django_openid.consumer.SessionConsumer',
'django.contrib.messages.middleware.MessageMiddleware',
'groups.middleware.GroupAwareMiddleware',
'pinax.apps.account.middleware.AuthenticatedMiddleware',
'pinax.apps.account.middleware.LocaleMiddleware',
'django.middleware.doc.XViewMiddleware',
'pagination.middleware.PaginationMiddleware',
'django_sorting.middleware.SortingMiddleware',
'pinax.middleware.security.HideSensistiveFieldsMiddleware',
'debug_toolbar.middleware.DebugToolbarMiddleware']
Template error:
In template /Users/nb/Desktop/myenv2/lib/python2.7/site-packages/debug_toolbar/templates/debug_toolbar/base.html, error at line 48
Caught AttributeError while rendering: 'AddRatingFromModel' object has no attribute '__name__'
38 : </div>
39 : {% for panel in panels %}
40 : {% if panel.has_content %}
41 : <div id="{{ panel.dom_id }}" class="panelContent">
42 : <div class="djDebugPanelTitle">
43 : {% trans "Close" %}
44 : <h3>{{ panel.title|safe }}</h3>
45 : </div>
46 : <div class="djDebugPanelContent">
47 : <div class="scroll">
48 : {{ panel.content|safe }}
49 : </div>
50 : </div>
51 : </div>
52 : {% endif %}
53 : {% endfor %}
54 : <div id="djDebugWindow" class="panelContent"></div>
55 : </div>
56 :
Traceback:
File "/Users/nb/Desktop/myenv2/lib/python2.7/site-packages/django/core/handlers/base.py" in get_response
178. response = middleware_method(request, response)
File "/Users/nb/Desktop/myenv2/lib/python2.7/site-packages/debug_toolbar/middleware.py" in process_response
104. smart_unicode(self.debug_toolbars[request].render_toolbar() + self.tag))
File "/Users/nb/Desktop/myenv2/lib/python2.7/site-packages/debug_toolbar/toolbar/loader.py" in render_toolbar
78. return render_to_string('debug_toolbar/base.html', context)
File "/Users/nb/Desktop/myenv2/lib/python2.7/site-packages/django/template/loader.py" in render_to_string
183. return t.render(Context(dictionary))
File "/Users/nb/Desktop/myenv2/lib/python2.7/site-packages/django/test/utils.py" in instrumented_test_render
60. return self.nodelist.render(context)
File "/Users/nb/Desktop/myenv2/lib/python2.7/site-packages/django/template/base.py" in render
744. bits.append(self.render_node(node, context))
File "/Users/nb/Desktop/myenv2/lib/python2.7/site-packages/django/template/debug.py" in render_node
73. result = node.render(context)
File "/Users/nb/Desktop/myenv2/lib/python2.7/site-packages/django/template/defaulttags.py" in render
227. nodelist.append(node.render(context))
File "/Users/nb/Desktop/myenv2/lib/python2.7/site-packages/django/template/defaulttags.py" in render
311. return self.nodelist_true.render(context)
File "/Users/nb/Desktop/myenv2/lib/python2.7/site-packages/django/template/base.py" in render
744. bits.append(self.render_node(node, context))
File "/Users/nb/Desktop/myenv2/lib/python2.7/site-packages/django/template/debug.py" in render_node
73. result = node.render(context)
File "/Users/nb/Desktop/myenv2/lib/python2.7/site-packages/django/template/debug.py" in render
90. output = self.filter_expression.resolve(context)
File "/Users/nb/Desktop/myenv2/lib/python2.7/site-packages/django/template/base.py" in resolve
510. obj = self.var.resolve(context)
File "/Users/nb/Desktop/myenv2/lib/python2.7/site-packages/django/template/base.py" in resolve
653. value = self._resolve_lookup(context)
File "/Users/nb/Desktop/myenv2/lib/python2.7/site-packages/django/template/base.py" in _resolve_lookup
698. current = current()
File "/Users/nb/Desktop/myenv2/lib/python2.7/site-packages/debug_toolbar/panels/request_vars.py" in content
35. 'view_func': '%s.%s' % (self.view_func.__module__, self.view_func.__name__),
Exception Type: TemplateSyntaxError at /spiceapp/rate/1/2/
Exception Value: Caught AttributeError while rendering: 'AddRatingFromModel' object has no attribute '__name__'

This looks like an old bug in django-debug-toolbar. Do you happen to know which version you are using? Because the file looks like the one in this commit. Several fixes has been made to that file since then: this one, for example seems to address specifically your issue.
In any case, the version you're using seems to predate the 2nd of June, 2011. I would try looking into updating your environment.

Related

django-debug-toolbar: 'list' does not support the buffer interface

I made a few modifications to my model, adding some image fields and installing Pillow, deleteing some models or model fields.
As Site is not yet in production, I simply dropped the database and re-created it, and synced it. Then I got this error.
I can't figure out what could be the source of this sudden error. In the settings.py I added a media_root but nothing else.
Environment:
Request Method: GET
Request URL: http://localhost:8000/
Django Version: 1.6.2
Python Version: 3.4.0
Installed Applications:
('django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'backoffice',
'public',
'django.contrib.sites',
'allauth',
'allauth.account',
'allauth.socialaccount',
'allauth.socialaccount.providers.facebook',
'allauth.socialaccount.providers.google',
'allauth.socialaccount.providers.twitter',
'widget_tweaks',
'rosetta',
'debug_toolbar',
'template_debug')
Installed Middleware:
('debug_toolbar.middleware.DebugToolbarMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.locale.LocaleMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware')
Template error:
In template C:\Python34\lib\site-packages\debug_toolbar\templates\debug_toolbar\base.html, error at line 5
'list' does not support the buffer interface
1 : {% load i18n %}{% load static from staticfiles %}{% load url from future %}
2 : <style type="text/css">
3 : #media print { #djDebug {display:none;}}
4 : </style>
5 : <link rel="stylesheet" href=" {% static 'debug_toolbar/css/toolbar.css' %} " type="text/css" />
6 : {% if toolbar.config.JQUERY_URL %}
7 : <script src="{{ toolbar.config.JQUERY_URL }}"></script>
8 : <script>var djdt = {jQuery: jQuery.noConflict(true)};</script>
9 : {% else %}
10 : <script>var djdt = {jQuery: jQuery};</script>
11 : {% endif %}
12 : <script src="{% static 'debug_toolbar/js/toolbar.js' %}"></script>
13 : <div id="djDebug" style="display:none;" dir="ltr"
14 : data-store-id="{{ toolbar.store_id }}" data-render-panel-url="{% url 'djdt:render_panel' %}"
15 : {{ toolbar.config.ROOT_TAG_EXTRA_ATTRS|safe }}>
Traceback:
File "C:\Python34\lib\site-packages\django\core\handlers\base.py" in get_response
201. response = middleware_method(request, response)
File "C:\Python34\lib\site-packages\debug_toolbar\middleware.py" in process_response
121. bits[-2] += toolbar.render_toolbar()
File "C:\Python34\lib\site-packages\debug_toolbar\toolbar.py" in render_toolbar
68. return render_to_string('debug_toolbar/base.html', context)
File "C:\Python34\lib\site-packages\django\template\loader.py" in render_to_string
164. return t.render(Context(dictionary))
File "C:\Python34\lib\site-packages\django\template\base.py" in render
140. return self._render(context)
File "C:\Python34\lib\site-packages\django\test\utils.py" in instrumented_test_render
85. return self.nodelist.render(context)
File "C:\Python34\lib\site-packages\django\template\base.py" in render
840. bit = self.render_node(node, context)
File "C:\Python34\lib\site-packages\django\template\debug.py" in render_node
78. return node.render(context)
File "C:\Python34\lib\site-packages\django\templatetags\static.py" in render
106. url = self.url(context)
File "C:\Python34\lib\site-packages\django\contrib\staticfiles\templatetags\staticfiles.py" in url
12. return staticfiles_storage.url(path)
File "C:\Python34\lib\site-packages\django\utils\functional.py" in inner
213. self._setup()
File "C:\Python34\lib\site-packages\django\contrib\staticfiles\storage.py" in _setup
311. self._wrapped = get_storage_class(settings.STATICFILES_STORAGE)()
File "C:\Python34\lib\site-packages\django\contrib\staticfiles\storage.py" in __init__
37. *args, **kwargs)
File "C:\Python34\lib\site-packages\django\core\files\storage.py" in __init__
154. self.location = abspathu(self.base_location)
File "C:\Python34\lib\ntpath.py" in abspath
545. path = _getfullpathname(path)
Exception Type: TypeError at /
Exception Value: 'list' does not support the buffer interface
All right, my fault. Error was in fact pretty explicit.
Unlike the TEMPLATE_DIRS, MEDIA_ROOT is not supposed to be a list.
Django Debug toolbar will return an error every time you mess up with variables types in
the "settings.py" file.
In case anyone does similar mistakes, I'll leave Q&A here.

'str' object has no attribute 'attname'

I am trying to display a link to the next and previous object according the title field using get_next_or_previous_by_FIELD. Django 1.6 is throwing me this error.
Error during template rendering
'str' object has no attribute 'attname'
Error occurs here in template.
{% with next_lesson=lesson.get_next_by_title %}
And here in my models.
return self._get_next_or_previous_by_FIELD('title', is_next=True)
Here is my model.
class LessonManager(models.Manager):
def all(self):
return super(LessonManager, self).filter(active=True)
class Lesson(models.Model):
active = models.BooleanField(default=False)
title = models.CharField(max_length=65)
slug = models.SlugField(unique=True)
objects = LessonManager()
def __unicode__(self, ):
return self.title
class Meta:
ordering = ['title']
def get_absolute_url(self):
return reverse('lesson', args=[str(self.slug)])
def get_next_by_title(self):
try:
return self._get_next_or_previous_by_FIELD('title', is_next=True)
except Lesson.DoesNotExist:
return None
def get_previous_by_title(self):
try:
return self._get_next_or_previous_by_FIELD(order='title', is_next=False)
except Lesson.DoesNotExist:
return None
And here is my template.
<a class="col-md-6" href="{{ lesson.get_previous_by_title.get_absolute_url }}" title="{% trans "View previous post" %}">« {{ lesson.get_previous_by_title.title }}</a>
<a class="col-md-6" href="{{ lesson.get_next_by_title.get_absolute_url }}" title="{% trans "View previous post" %}">« {{ lesson.get_next_by_title.title }}</a>
Here is the full traceback as requested.
Environment:
Request Method: GET
Request URL: /tutorials/lesson/lesson-name/
Django Version: 1.6.2
Python Version: 2.7.6
Installed Applications:
('django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'blog',
'ckeditor',
'tutorials')
Installed Middleware:
('django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware')
Template error:
In template C:\Users\Shaun\Desktop\sg\static\templates\tutorials\lesson.html, error at line 22
'str' object has no attribute 'attname'
12 : {% endif %}
13 : {% if lesson.get_next_by_timestamp %}
14 : <a class="right" href="{{ lesson.get_next_post.get_absolute_url }}">{{ lesson.get_next_post.title|truncatewords:'4' }} »</a>
15 : {% endif %}
16 :
17 : <div class='clearfix'></div>
18 :
19 : <h2>{{ lesson.title|upper }}</h2>
20 : <p>{{ lesson.content|safe }}</p>
21 :
22 : <a class="col-md-6" href=" {{ lesson.get_previous_by_title.get_absolute_url }} " title="{% trans "View previous post" %}">« {{ lesson.get_previous_by_title.title }}</a>
23 : <a class="col-md-6" href="{{ lesson.get_next_by_title.get_absolute_url }}" title="{% trans "View previous post" %}">« {{ lesson.get_next_by_title.title }}</a>
24 :
25 : {% endblock %}
Traceback:
File "C:\Users\Shaun\Desktop\sg\lib\site-packages\django\core\handlers\base.py" in get_response
114. response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "C:\Users\Shaun\Desktop\sg\src\tutorials\views.py" in single_lesson
13. return render_to_response('tutorials/lesson.html', locals(), context_instance=RequestContext(request))
File "C:\Users\Shaun\Desktop\sg\lib\site-packages\django\shortcuts\__init__.py" in render_to_response
29. return HttpResponse(loader.render_to_string(*args, **kwargs), **httpresponse_kwargs)
File "C:\Users\Shaun\Desktop\sg\lib\site-packages\django\template\loader.py" in render_to_string
169. return t.render(context_instance)
File "C:\Users\Shaun\Desktop\sg\lib\site-packages\django\template\base.py" in render
140. return self._render(context)
File "C:\Users\Shaun\Desktop\sg\lib\site-packages\django\template\base.py" in _render
134. return self.nodelist.render(context)
File "C:\Users\Shaun\Desktop\sg\lib\site-packages\django\template\base.py" in render
840. bit = self.render_node(node, context)
File "C:\Users\Shaun\Desktop\sg\lib\site-packages\django\template\debug.py" in render_node
78. return node.render(context)
File "C:\Users\Shaun\Desktop\sg\lib\site-packages\django\template\loader_tags.py" in render
123. return compiled_parent._render(context)
File "C:\Users\Shaun\Desktop\sg\lib\site-packages\django\template\base.py" in _render
134. return self.nodelist.render(context)
File "C:\Users\Shaun\Desktop\sg\lib\site-packages\django\template\base.py" in render
840. bit = self.render_node(node, context)
File "C:\Users\Shaun\Desktop\sg\lib\site-packages\django\template\debug.py" in render_node
78. return node.render(context)
File "C:\Users\Shaun\Desktop\sg\lib\site-packages\django\template\loader_tags.py" in render
62. result = block.nodelist.render(context)
File "C:\Users\Shaun\Desktop\sg\lib\site-packages\django\template\base.py" in render
840. bit = self.render_node(node, context)
File "C:\Users\Shaun\Desktop\sg\lib\site-packages\django\template\debug.py" in render_node
78. return node.render(context)
File "C:\Users\Shaun\Desktop\sg\lib\site-packages\django\template\debug.py" in render
88. output = self.filter_expression.resolve(context)
File "C:\Users\Shaun\Desktop\sg\lib\site-packages\django\template\base.py" in resolve
585. obj = self.var.resolve(context)
File "C:\Users\Shaun\Desktop\sg\lib\site-packages\django\template\base.py" in resolve
735. value = self._resolve_lookup(context)
File "C:\Users\Shaun\Desktop\sg\lib\site-packages\django\template\base.py" in _resolve_lookup
789. current = current()
File "C:\Users\Shaun\Desktop\sg\src\tutorials\models.py" in get_previous_by_title
64. return self._get_next_or_previous_by_FIELD('title', is_next=False)
File "C:\Users\Shaun\Desktop\sg\lib\site-packages\django\db\models\base.py" in _get_next_or_previous_by_FIELD
708. param = force_text(getattr(self, field.attname))
Exception Type: AttributeError at /tutorials/lesson/setting-up-your-django-blog-application/
Exception Value: 'str' object has no attribute 'attname'
_get_next_or_previous_by_FIELD isn't supposed to be something you call yourself.
The main problem you're having is that it is expecting a Field object, not a string, hence the error. This is because the method is actually used as part of a curried function that is created by the field class itself, which in turn is called by the model metaclass when the model is first imported.
The currying creates the actual get_next_by_foo and get_previous_by_foo methods. In fact, these are only created for Date and Datetime fields.
Note that the uncurried method name begins with an underscore, which - with the exception of Model._meta - is a good sign that you're not supposed to be using it in your own code.

django-openid-auth: TemplateSyntaxError

I'm trying to set up django-openid-auth on my django project. I've followed steps 1-8 of the provided guide and have tried going to /openid/login/ on my server. However, when I go to that page I see
TemplateSyntaxError at /openid/login/
Could not parse the remainder: '-logo' from 'openid-logo'. The syntax of 'url' changed in Django 1.5, see the docs.
I'm a bit confused since this is in a template included in the app - I didn't write the template myself. If anybody knows what I'm doing wrong, I'd really appreciate some help.
Here's my stacktrace:
Environment:
Request Method: GET
Request URL: http://localhost:8000/openid/login/
Django Version: 1.5.2
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',
'wseeruploader.apps.fileupload',
'django_openid_auth',
'crispy_forms')
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')
Template error:
In template /usr/lib/python2.7/site-packages/django_openid_auth/templates/openid/login.html, error at line 8
Could not parse the remainder: '-logo' from 'openid-logo'. The syntax of 'url' changed in Django 1.5, see the docs.
1 : {% load i18n %}
2 : <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
3 : <html>
4 : <head>
5 : <title>Sign in with your OpenID</title>
6 : <style type="text/css">
7 : input.openid {
8 : background: url( {% url openid-logo %} ) no-repeat;
9 : background-position: 0 50%;
10 : padding-left: 16px;
11 : }
12 : </style>
13 : </head>
14 : <body>
15 : <h1>Sign in with your OpenID</h1>
16 : {% if form.errors %}
17 : <p class="errors">{% trans "Please correct errors below:" %}<br />
18 : {% if form.openid_identifier.errors %}
Traceback:
File "/usr/lib/python2.7/site-packages/django/core/handlers/base.py" in get_response
115. response = callback(request, *callback_args, **callback_kwargs)
File "/usr/lib/python2.7/site-packages/django_openid_auth/views.py" in login_begin
171. }, context_instance=RequestContext(request))
File "/usr/lib/python2.7/site-packages/django/shortcuts/__init__.py" in render_to_response
29. return HttpResponse(loader.render_to_string(*args, **kwargs), **httpresponse_kwargs)
File "/usr/lib/python2.7/site-packages/django/template/loader.py" in render_to_string
170. t = get_template(template_name)
File "/usr/lib/python2.7/site-packages/django/template/loader.py" in get_template
146. template, origin = find_template(template_name)
File "/usr/lib/python2.7/site-packages/django/template/loader.py" in find_template
135. source, display_name = loader(name, dirs)
File "/usr/lib/python2.7/site-packages/django/template/loader.py" in __call__
43. return self.load_template(template_name, template_dirs)
File "/usr/lib/python2.7/site-packages/django/template/loader.py" in load_template
49. template = get_template_from_string(source, origin, template_name)
File "/usr/lib/python2.7/site-packages/django/template/loader.py" in get_template_from_string
157. return Template(source, origin, name)
File "/usr/lib/python2.7/site-packages/django/template/base.py" in __init__
125. self.nodelist = compile_string(template_string, origin)
File "/usr/lib/python2.7/site-packages/django/template/base.py" in compile_string
153. return parser.parse()
File "/usr/lib/python2.7/site-packages/django/template/base.py" in parse
274. compiled_result = compile_func(self, token)
File "/usr/lib/python2.7/site-packages/django/template/defaulttags.py" in url
1266. viewname = parser.compile_filter(bits[1])
File "/usr/lib/python2.7/site-packages/django/template/base.py" in compile_filter
353. return FilterExpression(token, self)
File "/usr/lib/python2.7/site-packages/django/template/base.py" in __init__
570. "from '%s'" % (token[upto:], token))
Exception Type: TemplateSyntaxError at /openid/login/
Exception Value: Could not parse the remainder: '-logo' from 'openid-logo'. The syntax of 'url' changed in Django 1.5, see the docs.
Since you are using django-1.5
You should change:
{% url openid-logo %}
to
{% url 'openid-logo' %}
Relevant documentation can be found in the release notes
The upshot of this is that if you are not using {% load url from future %} in your templates, you’ll need to change tags like {% url myview %} to {% url "myview" %}. If you were using {% load url from future %} you can simply remove that line under Django 1.5

NoReverseMatch - Reverse for 'detail' with arguments and keyword arguments {} not found

for some reason I cannot seem to solve this bug. I am using Django 1.5
The actual error I get is
Reverse for 'detail' with arguments '()' and keyword arguments '{u'slug': u'third-post'}' not found.
In my projest dir I have this urls.py
from django.conf.urls import patterns, include, url
# Uncomment the next two lines to enable the admin:
from django.contrib import admin
admin.autodiscover()
urlpatterns = patterns('',
# Examples:
# url(r'^$', 'blog.views.home', name='home'),
# url(r'^blog/', include('blog.foo.urls')),
# Uncomment the admin/doc line below to enable admin documentation:
url(r'^admin/doc/', include('django.contrib.admindocs.urls')),
# Uncomment the next line to enable the admin:
url(r'^admin/', include(admin.site.urls)),
#include the blogapp url
url(r'', include('blogapp.urls', namespace='blog')),
)
The urls.py in my app folder looks like this
urlpatterns = patterns ('',
url(r'^$',
ListView.as_view(
queryset = Post.objects.order_by('-pub_date')[:5],
context_object_name = 'latest_posts',
template_name = 'blogapp/default.html'),
name = 'index'
),
url(r'^post/(?P<slug>\w+)/$',
PostDetailView.as_view(),
name = 'detail'
),
)
My post detail view looks like this
class PostDetailView(DetailView):
template_name = 'blogapp/post/detail.html'
def get_object(self):
return get_object_or_404(Post, slug__iexact = self.kwargs['slug'])
I have this in my html
{% for p in latest_posts %}
<li>{{p.title}}</li>
{% endfor %}
I can open my shell and I get a url back
>>> from django.core.urlresolvers import reverse
>>> reverse('blog:detail', kwargs={'slug':'test'})
'/post/test/'
The weird thing is in my html this line works
<li>{{p.title}}</li>
why would p.id work and not p.slug?
Here is the traceback
Environment:
Request Method: GET
Request URL: http://127.0.0.1:8000/
Django Version: 1.5
Python Version: 2.7.2
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',
'south',
'blogapp')
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')
Template error:
In template .../Development/Python/Django/dev/blog/blogapp/templates/blogapp/default.html, error at line 11
Reverse for 'detail' with arguments '()' and keyword arguments '{u'slug': u'third-post'}' not found.
1 : {% extends "blogapp/base.html" %}
2 :
3 : {% block title %}Blog Posts{% endblock %}
4 :
5 : {% block body %}
6 :
7 : {% if latest_posts %}
8 : <p>Latest 5 blog posts</p>
9 : <ul>
10 : {% for p in latest_posts %}
11 : <li>{{p.title}}</li>
12 : {% endfor %}
13 : </ul>
14 : {% else %}
15 : <p>No blog posts published.</p>
16 : {% endif %}
17 :
18 : {% endblock %}
19 :
20 :
Traceback:
File ".../.virtualenvs/env1/lib/python2.7/site-packages/django/core/handlers/base.py" in get_response
140. response = response.render()
File ".../.virtualenvs/env1/lib/python2.7/site-packages/django/template/response.py" in render
105. self.content = self.rendered_content
File ".../.virtualenvs/env1/lib/python2.7/site-packages/django/template/response.py" in rendered_content
82. content = template.render(context)
File ".../.virtualenvs/env1/lib/python2.7/site-packages/django/template/base.py" in render
140. return self._render(context)
File ".../.virtualenvs/env1/lib/python2.7/site-packages/django/template/base.py" in _render
134. return self.nodelist.render(context)
File ".../.virtualenvs/env1/lib/python2.7/site-packages/django/template/base.py" in render
830. bit = self.render_node(node, context)
File ".../.virtualenvs/env1/lib/python2.7/site-packages/django/template/debug.py" in render_node
74. return node.render(context)
File ".../.virtualenvs/env1/lib/python2.7/site-packages/django/template/loader_tags.py" in render
124. return compiled_parent._render(context)
File ".../.virtualenvs/env1/lib/python2.7/site-packages/django/template/base.py" in _render
134. return self.nodelist.render(context)
File ".../.virtualenvs/env1/lib/python2.7/site-packages/django/template/base.py" in render
830. bit = self.render_node(node, context)
File ".../.virtualenvs/env1/lib/python2.7/site-packages/django/template/debug.py" in render_node
74. return node.render(context)
File ".../.virtualenvs/env1/lib/python2.7/site-packages/django/template/loader_tags.py" in render
63. result = block.nodelist.render(context)
File ".../.virtualenvs/env1/lib/python2.7/site-packages/django/template/base.py" in render
830. bit = self.render_node(node, context)
File ".../.virtualenvs/env1/lib/python2.7/site-packages/django/template/debug.py" in render_node
74. return node.render(context)
File ".../.virtualenvs/env1/lib/python2.7/site-packages/django/template/defaulttags.py" in render
284. return nodelist.render(context)
File ".../.virtualenvs/env1/lib/python2.7/site-packages/django/template/base.py" in render
830. bit = self.render_node(node, context)
File ".../.virtualenvs/env1/lib/python2.7/site-packages/django/template/debug.py" in render_node
74. return node.render(context)
File ".../.virtualenvs/env1/lib/python2.7/site-packages/django/template/defaulttags.py" in render
188. nodelist.append(node.render(context))
File ".../.virtualenvs/env1/lib/python2.7/site-packages/django/template/defaulttags.py" in render
424. raise e
Exception Type: NoReverseMatch at /
Exception Value: Reverse for 'detail' with arguments '()' and keyword arguments '{u'slug': u'third-post'}' not found.
Because your url codes did not support this character "-", it must be
url(r'^post/(?P<slug>[\w\-]+)/$',
PostDetailView.as_view(),
name = 'detail'
),

WSGIRequest error using django_model_comments

Sorry to post yet another question related to the error:
'WSGIRequest' object has no attribute 'find'
But I really can't find the answer anywhere.
I'm trying to use the django_model_comments app, which extends django's included comment app.
Did everything the page tells, however when running the server, I get the following:
Environment:
Request Method: GET
Request URL: http://localhost:8000/feed/1
Django Version: 1.4.3
Python Version: 2.7.2
Installed Applications:
['django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.messages',
'django.contrib.staticfiles',
'model_comments',
'django.contrib.comments',
'pinax_theme_bootstrap_account',
'pinax_theme_bootstrap',
'django_forms_bootstrap',
'account',
'metron',
'user_app',
'feed_app']
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']
Template error:
In template D:\Docs\Work\repo\project\feed_app\templates\feed.html, error at line 10
'WSGIRequest' object has no attribute 'find'
1 : {% load model_comment_tags %}
2 : {% get_comment_form for feed as post_form %}
3 : {% render_comment_form post_form %}
Traceback:
File "D:\Docs\Work\repo\so_virtual_env\lib\site-packages\django\core\handlers\base.py" in get_response
111. response = callback(request, *callback_args, **callback_kwargs)
File "D:\Docs\Work\repo\project\feed_app\views.py" in get_user_feed
37. 'feed': private_feed})
File "D:\Docs\Work\repo\so_virtual_env\lib\site-packages\django\template\base.py" in render
140. return self._render(context)
File "D:\Docs\Work\repo\so_virtual_env\lib\site-packages\django\template\base.py" in _render
134. return self.nodelist.render(context)
File "D:\Docs\Work\repo\so_virtual_env\lib\site-packages\django\template\base.py" in render
823. bit = self.render_node(node, context)
File "D:\Docs\Work\repo\so_virtual_env\lib\site-packages\django\template\debug.py" in render_node
74. return node.render(context)
File "D:\Docs\Work\repo\so_virtual_env\lib\site-packages\django\template\defaulttags.py" in render
281. return nodelist.render(context)
File "D:\Docs\Work\repo\so_virtual_env\lib\site-packages\django\template\base.py" in render
823. bit = self.render_node(node, context)
File "D:\Docs\Work\repo\so_virtual_env\lib\site-packages\django\template\debug.py" in render_node
74. return node.render(context)
File "D:\Docs\Work\repo\project\model_comments\templatetags\model_comment_tags.py" in render
26. return self.func(context)
File "D:\Docs\Work\repo\project\model_comments\templatetags\model_comment_tags.py" in wrap
75. form.set_request(request)
File "D:\Docs\Work\repo\project\model_comments\forms.py" in set_request
106. self.fields['from_url'].initial = unicode(Url(request))
File "D:\Docs\Work\repo\project\model_comments\url_util.py" in __init__
11. self.scheme, self.netloc, self.path, self.params, self.query_string, self.fragment = urlparse.urlparse(url)
File "C:\Python27\Lib\urlparse.py" in urlparse
134. tuple = urlsplit(url, scheme, allow_fragments)
File "C:\Python27\Lib\urlparse.py" in urlsplit
173. i = url.find(':')
Exception Type: AttributeError at /feed/1
Exception Value: 'WSGIRequest' object has no attribute 'find'
And the error happens when a templatetag is used:
html = "{% load model_comment_tags %} \
{% get_comment_form for feed as post_form %}\
{% render_comment_form post_form %}"
t = template.Template(html)
html = t.render(RequestContext(request, {'feed': private_feed}))
I've checked all my middleware, the order of apps, deleted .pyc files, and made all sorts of experiments in the template.
There's a bug in the django_model_comments library, because here they pass the HttpRequest object, not a string which is what the Url class here is expecting, so instead it should call the build_absolute_uri() method on the request object and then pass the string to the Url class.
So basically replace
unicode(Url(request))
with
unicode(Url(request.build_absolute_uri()))