Django new comments framework error

150 views
Skip to first unread message

Slavus

unread,
Aug 26, 2008, 8:55:49 AM8/26/08
to Django users
Today I updated Django to trunk version 8580, and I saw new comments
framework.
I updated my app acording to docs, made sql data migration but it
looks like new comments are not working.
I am getting:
Caught an exception while rendering: Reverse for '<function
post_comment at 0x01894770>' not found.

when I try to call render_comment_form ,or get_comment_form, and all
becasue of
{% comment_form_target %}, this seams to be the problem.

It is some kind of strange bug, Has someone some kind of clue what I
can do to fix this.
Thanx,

Below is original trace:


Original Traceback (most recent call last):
File "D:\dev\django-svn\django\template\debug.py", line 71, in
render_node
result = node.render(context)
File "D:\dev\django-svn\django\template\__init__.py", line 876, in
render
return func(*resolved_vars)
File "D:\dev\django-svn\django\contrib\comments\templatetags
\comments.py", line 245, in comment_form_target
return comments.get_form_target()
File "D:\dev\django-svn\django\contrib\comments\__init__.py", line
43, in get_form_target
return
urlresolvers.reverse("django.contrib.comments.views.comments.post_comment")
File "D:\dev\django-svn\django\core\urlresolvers.py", line 307, in
reverse
*args, **kwargs)))
File "D:\dev\django-svn\django\core\urlresolvers.py", line 291, in
reverse
raise NoReverseMatch("Reverse for '%s' not found." % lookup_view)
NoReverseMatch: Reverse for '<function post_comment at 0x01894770>'
not found.Request Method: GET
Request URL: http://localhost/article/novi/
Exception Type: TemplateSyntaxError
Exception Value: Caught an exception while rendering: Reverse for
'<function post_comment at 0x01894770>' not found.

Original Traceback (most recent call last):
File "D:\dev\django-svn\django\template\debug.py", line 71, in
render_node
result = node.render(context)
File "D:\dev\django-svn\django\template\__init__.py", line 876, in
render
return func(*resolved_vars)
File "D:\dev\django-svn\django\contrib\comments\templatetags
\comments.py", line 245, in comment_form_target
return comments.get_form_target()
File "D:\dev\django-svn\django\contrib\comments\__init__.py", line
43, in get_form_target
return
urlresolvers.reverse("django.contrib.comments.views.comments.post_comment")
File "D:\dev\django-svn\django\core\urlresolvers.py", line 307, in
reverse
*args, **kwargs)))
File "D:\dev\django-svn\django\core\urlresolvers.py", line 291, in
reverse
raise NoReverseMatch("Reverse for '%s' not found." % lookup_view)
NoReverseMatch: Reverse for '<function post_comment at 0x01894770>'
not found.

hotani

unread,
Aug 26, 2008, 1:21:43 PM8/26/08
to Django users
No idea. I seem to be getting the same thing.

The comments upgrade has caused all kinds of meltdowns in my
applications. For one, updating the SQL failed. PostgreSQL was
complaining because it was updating fields set to "NOT NULL" with null
values. I changed the query to accommodate for this, now I can't seem
to render a comment form at all.

{% render_comment_form for object as f %} => fails with "'NoneType'
object has no attribute 'source'"
{% render_comment_form for object %} (this is straight from the docs)
=> fails: "Caught an exception while rendering: Reverse for '<function
post_comment at 0xfc28b18>' not found."

hotani

unread,
Aug 26, 2008, 1:37:32 PM8/26/08
to Django users
This ended up working (I honestly don't remember which tinker finally
did it...):
{% render_comment_form for object %}

I also had to make an additional change in urls:
old way="django.contrib.comments.urls.comments"
new="django.contrib.comments.urls"

At least things are showing up now and not exploding.

hotani

unread,
Aug 26, 2008, 10:46:14 PM8/26/08
to Django users
Well it happened again when I uploaded the comment changes to another
server.

Here's the fix: go to /django/contrib/comments and wipe out the .pyc
files:
sudo rm */*.pyc

that finally fixed it.

Slavus

unread,
Aug 27, 2008, 2:54:34 AM8/27/08
to Django users
Here is the solution:
You'll get this if you still have stale pyc files left over from the
old comment system. Delete 'em and your code will work.

Mark

unread,
Aug 28, 2008, 4:57:07 AM8/28/08
to Django users
Hi,

Updated to 8613 with the release of Django 1.0 Beta 2 and saw the
addition of commenting framework - tried to add it and am getting a
similar error to above.
I tried this (even though I did not use the old commenting system).

Here is the exception information...
----------------------------------------------------------------------------------------------------
Environment:

Request Method: GET
Request URL: http://localhost/apps/buildboard/builddetails/80/
Django Version: 1.0-beta_1-SVN-unknown
Python Version: 2.5.1
Installed Applications:
['django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.admin',
'django_apps.buildboard',
'django_xmlrpc',
'django.contrib.comments']
Installed Middleware:
('django.middleware.common.CommonMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.middleware.doc.XViewMiddleware')


Template error:
In template c:\_tools\python251\lib\site-packages\django\contrib
\comments\templates\comments\form.html, error at line 2
Caught an exception while rendering: Reverse for '<function
post_comment at 0x0158BEF0>' not found.
1 : {% load comments %}


2 : <form action=" {% comment_form_target %} " method="POST">


3 : {% for field in form %}


4 : {% if field.is_hidden %}


5 : {{ field }}


6 : {% else %}


7 : <p


8 : {% if field.errors %} class="error"{% endif %}


9 : {% ifequal field.name "honeypot" %}
style="display:none;"{% endifequal %}>


10 : {% if field.errors %}{{ field.errors }}{% endif %}


11 : {{ field.label_tag }} {{ field }}


12 : </p>


Traceback:
File "c:\_tools\python251\lib\site-packages\django\core\handlers
\base.py" in get_response
86. response = callback(request, *callback_args,
**callback_kwargs)
File "c:\_tools\python251\lib\site-packages\django\contrib\auth
\decorators.py" in __call__
67. return self.view_func(request, *args, **kwargs)
File "c:\_projects\django_apps\..\django_apps\buildboard\views.py" in
build_details
309. print t.render(c)
File "c:\_tools\python251\lib\site-packages\django\template
\__init__.py" in render
176. return self.nodelist.render(context)
File "c:\_tools\python251\lib\site-packages\django\template
\__init__.py" in render
756. bits.append(self.render_node(node, context))
File "c:\_tools\python251\lib\site-packages\django\template\debug.py"
in render_node
71. result = node.render(context)
File "c:\_tools\python251\lib\site-packages\django\contrib\comments
\templatetags\comments.py" in render
158. formstr = render_to_string(template_search_list,
{"form" : self.get_form(context)}, context)
File "c:\_tools\python251\lib\site-packages\django\template\loader.py"
in render_to_string
107. return t.render(context_instance)
File "c:\_tools\python251\lib\site-packages\django\template
\__init__.py" in render
176. return self.nodelist.render(context)
File "c:\_tools\python251\lib\site-packages\django\template
\__init__.py" in render
756. bits.append(self.render_node(node, context))
File "c:\_tools\python251\lib\site-packages\django\template\debug.py"
in render_node
81. raise wrapped

Exception Type: TemplateSyntaxError at /apps/buildboard/builddetails/
80/
Exception Value: Caught an exception while rendering: Reverse for
'<function post_comment at 0x0158BEF0>' not found.

Original Traceback (most recent call last):
File "c:\_tools\python251\lib\site-packages\django\template
\debug.py", line 71, in render_node
result = node.render(context)
File "c:\_tools\python251\lib\site-packages\django\template
\__init__.py", line 876, in render
return func(*resolved_vars)
File "c:\_tools\python251\lib\site-packages\django\contrib\comments
\templatetags\comments.py", line 245, in comment_form_target
return comments.get_form_target()
File "c:\_tools\python251\lib\site-packages\django\contrib\comments
\__init__.py", line 50, in get_form_target
return
urlresolvers.reverse("django.contrib.comments.views.comments.post_comment")
File "c:\_tools\python251\lib\site-packages\django\core
\urlresolvers.py", line 307, in reverse
*args, **kwargs)))
File "c:\_tools\python251\lib\site-packages\django\core
\urlresolvers.py", line 291, in reverse
raise NoReverseMatch("Reverse for '%s' not found." % lookup_view)
NoReverseMatch: Reverse for '<function post_comment at 0x0158BEF0>'
not found.

----------------------------------------------------------------------------------------------------

The code that is causing this... (in a view method for debug
purposes...)
from django.template import Template, Context
t=Template('{% load comments %}{% render_comment_form for
buildboard.build 1 %}') # also tried using model instance, with
appropriate context entry.
c=Context({})
print t.render(c)

Do you need more information from me?

Thanks
Mark

hotani

unread,
Aug 28, 2008, 11:29:07 PM8/28/08
to Django users
Did you delete the .pyc files from the django source? Another approach
would be to go into /django/contrib/ and delete the comments
directory, then do an 'svn up' to restore it. Then you'll be sure to
get a fresh copy.

That is what worked for me. But if you haven't used the comment system
before then there shouldn't even be any pyc files in there, so I don't
know what is going on.

tonemcd

unread,
Aug 29, 2008, 2:40:26 AM8/29/08
to Django users
Also see
http://groups.google.com/group/django-users/browse_thread/thread/1f4bb991f9f0f7b5/62005ad4330c4884?lnk=gst&q=noReverseMatch#62005ad4330c4884

Short summary: maybe your named url regexes aren't matching the
variables passed to them in the {% url ... %} tag.

Apply the patch from http://code.djangoproject.com/ticket/8221 and
you'll know for certain if that's it.

Zapping old .pyc files can't hurt too!

Cheers,
Tone

tonemcd

unread,
Aug 30, 2008, 10:28:13 AM8/30/08
to Django users
...and of course, I find that http://code.djangoproject.com/ticket/8221
is now fixed!

That should help clear up an awful lot of confusion.

As of r8672, it's in the trunk.

Cheers,
Tone

On Aug 29, 7:40 am, tonemcd <tony.mcdon...@gmail.com> wrote:
> Also seehttp://groups.google.com/group/django-users/browse_thread/thread/1f4b...
> > >     raiseNoReverseMatch("Reverse for '%s' not found." % lookup_view)

SammyRulez

unread,
Sep 1, 2008, 9:27:43 AM9/1/08
to Django users
zapped django from site-packeges, updated to 8797 but still have this
error. Running the django/test over a fresh checkout got a lot of
fails on comments contrib app.

es


ERROR: testRenderCommentFormFromLiteral
(regressiontests.comment_tests.tests.templatetag_tests.CommentTemplateTagTests)
----------------------------------------------------------------------
Traceback (most recent call last):
File "C:\WORK\libs\djtrunk\tests\regressiontests\comment_tests\tests
\templatetag_tests.py", line 37, in testRenderCommentFormFromLiteral
self.testRenderCommentForm("{% render_comment_form for
comment_tests.article 1 %}")
File "C:\WORK\libs\djtrunk\tests\regressiontests\comment_tests\tests
\templatetag_tests.py", line 32, in testRenderCommentForm
ctx, out = self.render(t, a=Article.objects.get(pk=1))
File "C:\WORK\libs\djtrunk\tests\regressiontests\comment_tests\tests
\templatetag_tests.py", line 11, in render
out = Template(t).render(ctx)
File "C:\Python25\Lib\site-packages\django\test\utils.py", line 15,
in instrumented_test_render
return self.nodelist.render(context)
File "C:\Python25\Lib\site-packages\django\template\__init__.py",
line 768, in render
bits.append(self.render_node(node, context))
File "C:\Python25\Lib\site-packages\django\template\debug.py", line
71, in render_node
result = node.render(context)
File "C:\Python25\Lib\site-packages\django\contrib\comments
\templatetags\comments.py", line 159, in render
formstr = render_to_string(template_search_list, {"form" :
self.get_form(context)}, context)
File "C:\Python25\Lib\site-packages\django\template\loader.py", line
107, in render_to_string
return t.render(context_instance)
File "C:\Python25\Lib\site-packages\django\test\utils.py", line 15,
in instrumented_test_render
return self.nodelist.render(context)
File "C:\Python25\Lib\site-packages\django\template\__init__.py",
line 768, in render
bits.append(self.render_node(node, context))
File "C:\Python25\Lib\site-packages\django\template\debug.py", line
81, in render_node
raise wrapped
TemplateSyntaxError: Caught an exception while rendering: Reverse for
'<function post_comment at 0x034B2DB0>' with arguments '()' and
keyword arguments '{}' not found.

Original Traceback (most recent call last):
File "C:\Python25\Lib\site-packages\django\template\debug.py", line
71, in render_node
result = node.render(context)
File "C:\Python25\Lib\site-packages\django\template\__init__.py",
line 888, in render
return func(*resolved_vars)
File "C:\Python25\Lib\site-packages\django\contrib\comments
\templatetags\comments.py", line 246, in comment_form_target
return comments.get_form_target()
File "C:\Python25\Lib\site-packages\django\contrib\comments
\__init__.py", line 50, in get_form_target
return
urlresolvers.reverse("django.contrib.comments.views.comments.post_comment")
File "C:\Python25\Lib\site-packages\django\core\urlresolvers.py",
line 252, in reverse
*args, **kwargs)))
File "C:\Python25\Lib\site-packages\django\core\urlresolvers.py",
line 241, in reverse
"arguments '%s' not found." % (lookup_view, args, kwargs))
NoReverseMatch: Reverse for '<function post_comment at 0x034B2DB0>'
with arguments '()' and keyword arguments '{}' not found.


On 30 Ago, 16:28, tonemcd <tony.mcdon...@gmail.com> wrote:
> ...and of course, I find thathttp://code.djangoproject.com/ticket/8221
> > > >post_commentat 0x0158BEF0>' not found.
> > > > '<functionpost_commentat 0x0158BEF0>' not found.
>
> > > > Original Traceback (most recent call last):
> > > >   File "c:\_tools\python251\lib\site-packages\django\template
> > > > \debug.py", line 71, in render_node
> > > >     result = node.render(context)
> > > >   File "c:\_tools\python251\lib\site-packages\django\template
> > > > \__init__.py", line 876, in render
> > > >     return func(*resolved_vars)
> > > >   File "c:\_tools\python251\lib\site-packages\django\contrib\comments
> > > > \templatetags\comments.py", line 245, in comment_form_target
> > > >     return comments.get_form_target()
> > > >   File "c:\_tools\python251\lib\site-packages\django\contrib\comments
> > > > \__init__.py", line 50, in get_form_target
> > > >     return
> > > > urlresolvers.reverse("django.contrib.comments.views.comments.post_comment")
> > > >   File "c:\_tools\python251\lib\site-packages\django\core
> > > > \urlresolvers.py", line 307, inreverse
> > > >     *args, **kwargs)))
> > > >   File "c:\_tools\python251\lib\site-packages\django\core
> > > > \urlresolvers.py", line 291, inreverse
> > > >     raiseNoReverseMatch("Reversefor '%s' not found." % lookup_view)
> > > >NoReverseMatch:Reversefor '<functionpost_commentat 0x0158BEF0>'

Mark

unread,
Sep 16, 2008, 1:31:10 PM9/16/08
to Django users
Hi,

Finally - I got comments to work - but not correctly :-(

Django version - svn:9003

Urls conf ..
(r'^comments/', include('django.contrib.comments.urls')),

I tried everything:
- Deleted django/contrib/comments*.pyc files (a number of times)
- updated to svn latest (a number of times :) )

I finally got an idea from another thread in this group - where
someone said if they manually added the django.contrib.comments.urls
directly to their app url conf then it worked. I did that - and I got
it working too.

But that leaves my wondering why I can't it working the way it's
documented.

One thing that I noticed is that the django/contrib/comments/urls.py
is not getting imported (no pyc file is being created).

So the problem I am having must be due to URL confs, and more than
likely to this urlconf not being included correctly :-(

The following doesn' t work in my app urls.py...
urlpatterns += patterns('',
(r'^comments/', include('django.contrib.comments.urls')),
)

But in the same app urls.py the following DOES work...
urlpatterns += patterns('django.contrib.comments.views',
url(r'^comments/post/$', 'comments.post_comment',
name='comments-post-comment'),
url(r'^comments/posted/$', 'comments.comment_done',
name='comments-comment-done'),
url(r'^comments/flag/(\d+)/$', 'moderation.flag',
name='comments-flag'),
url(r'^comments/flagged/$', 'moderation.flag_done',
name='comments-flag-done'),
url(r'^comments/delete/(\d+)/$', 'moderation.delete',
name='comments-delete'),
url(r'^comments/deleted/$', 'moderation.delete_done',
name='comments-delete-done'),
url(r'^comments/moderate/$', 'moderation.moderation_queue',
name='comments-moderation-queue'),
url(r'^comments/approve/(\d+)/$', 'moderation.approve',
name='comments-approve'),
url(r'^comments/approved/$', 'moderation.approve_done',
name='comments-approve-done'),
)

urlpatterns += patterns('',
url(r'^comments/cr/(\d+)/(\w+)/$',
'django.views.defaults.shortcut', name='comments-url-redirect'),
)

Any ideas?

Thanks
Mark

Jonathan Nelson

unread,
Sep 17, 2008, 6:52:44 AM9/17/08
to Django users
If it's any consolation, I've had the the same bugs. I kept getting
the same reverse lookup function error whenever I tried to render the
comments form. I looked through all my comments directories, and
deleted all .pyc files. I finally got rid of all my reverse()
problems after I searched my entire hard drive and deleted every .pyc
file on it.

After that, I was having the same url problems that you had, Mark. I
tried the fix that you posted, and I finally got it to work. I was
never able to get it to work as documented.

I finally gave up on the comments thing, and I decided that I'm going
to roll my own comments system in a couple of weeks. I would have to
tweak the current comments framework substantially anyway to fit what
I need, regardless.

Jonathan

Jarek Zgoda

unread,
Sep 17, 2008, 7:01:06 AM9/17/08
to django...@googlegroups.com
Wiadomość napisana w dniu 2008-09-16, o godz. 19:31, przez Mark:

> I tried everything:
> - Deleted django/contrib/comments*.pyc files (a number of times)
> - updated to svn latest (a number of times :) )


That's not "everything" ;). Doing rm -rf django/contrib/comments was
the thing I did. And it worked too.

--
We read Knuth so you don't have to. - Tim Peters

Jarek Zgoda, R&D, Redefine
jarek...@redefine.pl

Mark

unread,
Sep 17, 2008, 12:26:35 PM9/17/08
to Django users


On Sep 17, 7:01 am, Jarek Zgoda <jarek.zg...@redefine.pl> wrote:
> Wiadomość napisana w dniu 2008-09-16, o godz. 19:31, przez Mark:
>
> > I tried everything:
> > - Deleted django/contrib/comments*.pyc files (a number of times)
> > - updated to svn latest (a number of times :) )
>
> That's not "everything" ;). Doing rm -rf django/contrib/comments was  
> the thing I did. And it worked too.
>

Before every svn update I do rm -rf django!! (or the equiv on windows
rd /s django)

> --
> We read Knuth so you don't have to. - Tim Peters
>
> Jarek Zgoda, R&D, Redefine
> jarek.zg...@redefine.pl

Mark

hotani

unread,
Oct 1, 2008, 3:53:48 PM10/1/08
to Django users
It's back!

No error on dev server, but crashing like crazy on test with same old
crap:
>> Caught an exception while rendering: Reverse for '<function post_comment at 0x2ae96d979410>' with arguments '()' and keyword arguments '{}' not found

It alternates between that and:
>> Caught an exception while rendering: No module named urls

Then the error page goes on to show the error is being caused by the
"{% comment_form_target %}" tag.

I have removed .pyc files. I have removed all of django and reloaded
it. What is left? This was working moments ago, and is fine on one
server but not another.

DavidA

unread,
Nov 13, 2008, 10:01:20 AM11/13/08
to Django users
I just got bit by this too and it turned out that I had done an
install of Django-1.0 on top of an older Django install. In the site-
packages directory there was both a django/contrib/comments/urls.py
(from 1.0) and a django/contrib/comments/urls/ directory which
contained __init__.py and comments.py.

So the configuration of comments using this line:

(r'^comments/', include('django.contrib.comments.urls')),

Was just importing the empty __init__.py and no urlpatterns variable
was defined. Thus, urlresolvers.reverse never saw any urlpatterns for
comments and couldn't reverse the post_comment view.

Just thought I'd post this in case someone else runs into the same
thing.

-Dave

On Oct 1, 2:53 pm, hotani <hot...@gmail.com> wrote:
> It's back!
>
> No error on dev server, but crashing like crazy on test with same old
> crap:
>
> >> Caught an exception while rendering:Reversefor '<functionpost_commentat 0x2ae96d979410>' with arguments '()' and keyword arguments '{}' not found

Greg Taylor

unread,
Nov 19, 2008, 11:51:37 AM11/19/08
to Django users
I've been seeing this same exact issue, even after completely deleting
and re-exporting Django and my project's source (minus all .pyc
files). It appears to be something else that's being buried by that
non-descriptive error message.

On Oct 1, 2:53 pm, hotani <hot...@gmail.com> wrote:
> It's back!
>
> No error on dev server, but crashing like crazy on test with same old
> crap:
>
> >> Caught an exception while rendering:Reversefor '<function post_comment at 0x2ae96d979410>' with arguments '()' and keyword arguments '{}'notfound
Reply all
Reply to author
Forward
0 new messages