Opened 16 years ago

Closed 16 years ago

Last modified 15 years ago

#8571 closed (worksforme)

comment framework throws obscure exception in {% comment_form_target %}

Reported by: slavus@… Owned by: nobody
Component: contrib.comments Version: 1.0
Severity: Keywords: comment, comment_form_target
Cc: django@… Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

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.

Change History (28)

comment:1 by Jacob, 16 years ago

Resolution: worksforme
Status: newclosed

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.

comment:2 by Aaron C. de Bruyn, 16 years ago

Cc: django@… added
Resolution: worksforme
Status: closedreopened

I am getting the same error. I stopped the development server, removed all the pyc files from my project, and from the python site-packages directory and still run into it. I deleted my site-packaged/django directory and reinstalled, same error. I fired up my clean virtual machine with Ubuntu Hardy, installed django from svn head, and checked out my project. Same error.

Environment:

Request Method: GET
Request URL: http://localhost:8000/oi/ticket/1/
Django Version: 1.0-beta_1-SVN-unknown
Python Version: 2.5.2
Installed Applications:
['django.contrib.auth',

'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.admin',
'django.contrib.databrowse',
'openiron.oi',
'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 /home/aaron/code/openiron/templates/ticket/ticket_detail.html, error at line 46

Caught an exception while rendering: Reverse for '<function post_comment at 0x88eba3c>' not found.
36 : {% get_comment_list for ticket as comment_list %}

37 : {% for comment in comment_list %}

38 : <TR class="{% cycle row1,row2 as rowclass %}">

39 : <TD{{ comment }}</TD>

40 : </TR>

41 : {% endfor %}

42 : </TABLE>

43 : {% endif %}

44 :

45 : {% get_comment_form for ticket as commentform %}

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

47 : {{ commentform }}

48 : <p class="submit">

49 : <input type="submit" name="submit" class="submit-post" value="Preview">

50 : </p>

51 : </form>

52 :

53 :

54 :

55 : <FORM ACTION="." METHOD="POST">

56 : <TABLE>

Traceback:
File "/usr/lib/python2.5/site-packages/django/core/handlers/base.py" in get_response

  1. response = callback(request, *callback_args, callback_kwargs)

File "/usr/lib/python2.5/site-packages/django/contrib/auth/decorators.py" in call

  1. return self.view_func(request, *args, kwargs)

File "/home/aaron/code/openiron/oi/views.py" in ticket_detail

  1. }, context_instance=RequestContext(request))

File "/usr/lib/python2.5/site-packages/django/shortcuts/init.py" in render_to_response

  1. return HttpResponse(loader.render_to_string(*args, kwargs), httpresponse_kwargs)

File "/usr/lib/python2.5/site-packages/django/template/loader.py" in render_to_string

  1. return t.render(context_instance)

File "/usr/lib/python2.5/site-packages/django/template/init.py" in render

  1. return self.nodelist.render(context)

File "/usr/lib/python2.5/site-packages/django/template/init.py" in render

  1. bits.append(self.render_node(node, context))

File "/usr/lib/python2.5/site-packages/django/template/debug.py" in render_node

  1. result = node.render(context)

File "/usr/lib/python2.5/site-packages/django/template/loader_tags.py" in render

  1. return compiled_parent.render(context)

File "/usr/lib/python2.5/site-packages/django/template/init.py" in render

  1. return self.nodelist.render(context)

File "/usr/lib/python2.5/site-packages/django/template/init.py" in render

  1. bits.append(self.render_node(node, context))

File "/usr/lib/python2.5/site-packages/django/template/debug.py" in render_node

  1. result = node.render(context)

File "/usr/lib/python2.5/site-packages/django/template/loader_tags.py" in render

  1. result = self.nodelist.render(context)

File "/usr/lib/python2.5/site-packages/django/template/init.py" in render

  1. bits.append(self.render_node(node, context))

File "/usr/lib/python2.5/site-packages/django/template/debug.py" in render_node

  1. raise wrapped

Exception Type: TemplateSyntaxError at /oi/ticket/1/
Exception Value: Caught an exception while rendering: Reverse for '<function post_comment at 0x88eba3c>' not found.

Original Traceback (most recent call last):

File "/usr/lib/python2.5/site-packages/django/template/debug.py", line 71, in render_node

result = node.render(context)

File "/usr/lib/python2.5/site-packages/django/template/init.py", line 876, in render

return func(*resolved_vars)

File "/usr/lib/python2.5/site-packages/django/contrib/comments/templatetags/comments.py", line 245, in comment_form_target

return comments.get_form_target()

File "/usr/lib/python2.5/site-packages/django/contrib/comments/init.py", line 50, in get_form_target

return urlresolvers.reverse("django.contrib.comments.views.comments.post_comment")

File "/usr/lib/python2.5/site-packages/django/core/urlresolvers.py", line 307, in reverse

*args, kwargs)))

File "/usr/lib/python2.5/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 0x88eba3c>' not found.

comment:3 by Thejaswi Puthraya, 16 years ago

Well, even I can't reproduce the error. Check out http://dpaste.com/74114/ for clarifications. Looks like you are using comments wrong or have misinterpreted the docs. I am leaving the ticket open with the hope that the reporter will close it after he has got the clarifications.

comment:4 by Aaron C. de Bruyn, 16 years ago

From your dpaste, I run lines 1 through 4 and end up with different results.
Since it was complaining about being unable to resolve the URL, I double-checked my urls.py file and found nothing out of order. All my calls to reverse work correctly--just not for comments. I do have django.contrib.comments in INSTALLED_APPS.

comment:5 by slavus@…, 16 years ago

Resolution: worksforme
Status: reopenedclosed

Thanx,
I have deleted old *.pyc files, and now it is working.
I would never thinhk that old pyc would make such problems.

comment:6 by Ole Morten Halvorsen, 16 years ago

I experienced the same issue, however once I cleared *.pyc files in Django it went away.

comment:7 by Alon Levy <alonlevy1@…>, 16 years ago

Hi, Just my twocents: I had the same problem, removing pyc didn't help (but it is always a good idea:), anyway, the problem was that my old urls.py read:

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

After some head scratching and looking for the non-existent help on contrib/comments (README file, anything), I did the following change and it seems to work (i.e. I'm on to the next problem from the 1.0 upgrade ;):

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

HTH,

Alon

comment:8 by killiands, 16 years ago

Resolution: worksforme
Status: closedreopened

Also got this error.
Template code:
{% load comments %}

{% block content %}

<h1>{{ object.title }}</h1>

<a href="{{ object.image.url }}"><img src="{{ object.get_display_url }}" alt="{{ object.title }}"/></a>

{% if object.caption %}<p>{{ object.caption }}</p>{% endif %}

{% get_comment_list for photologue.photo object.id as comment_list %}
{% for comment in comment_list %}

<div class="comment_{% cycle odd,even %}" id="c{{ comment.id }}">

<span class="comnum"><a id="c{{ comment.id }}" href="#c{{ comment.id }}">#{{ forloop.counter }}</a></span>
<p><b>{{ comment.person_name|escape }}</b> commented, on {{ comment.submit_date|date:"F j, Y" }} at {{ comment.submit_date|date:"P" }}:</p>
{{ comment.comment|escape|urlizetrunc:40|linebreaks }}

</div>

{% endfor %}

{% render_comment_form for object %}

{% endblock %}

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

comment:9 by Jacob, 16 years ago

Resolution: worksforme
Status: reopenedclosed

This is almost certainly either stale .pyc files in your tree, or an old version of Django on your path. If you can verify that that's not happening, reopen this ticket with the complete error.

Please, though, in the future use the "switch to copy and paste view" button to get a readable version of your error, and paste the contents of that error between {{{ and }}} (three braces) so that Trac knows to format it as code. Otherwise we can't read your errors!

comment:10 by psychcf, 16 years ago

milestone: 1.0post-1.0
Resolution: worksforme
Status: closedreopened
Version: SVN1.0

Ok, I've been having this problem in 1.0. I was hoping it would be fixed during the betas, but I guess it never did.

Here's my error log:

Environment:

Request Method: GET
Request URL: http://localhost:8080/blog/2008/sep/08/test-entry/
Django Version: 1.0-final-SVN-unknown
Python Version: 2.5.2
Installed Applications:
['django.contrib.auth',
 'django.contrib.contenttypes',
 'django.contrib.comments',
 'django.contrib.flatpages',
 'django.contrib.sessions',
 'django.contrib.sites',
 'django.contrib.markup',
 'django.contrib.admin',
 'desktopsite.apps.snapboard',
 'desktopsite.apps.comment_utils',
 'desktopsite.apps.blog',
 'desktopsite.apps.content',
 'desktopsite.apps.repository',
 'dojango']
Installed Middleware:
('django.middleware.common.CommonMiddleware',
 'django.contrib.sessions.middleware.SessionMiddleware',
 'django.contrib.auth.middleware.AuthenticationMiddleware',
 'django.middleware.doc.XViewMiddleware',
 'desktopsite.apps.snapboard.middleware.threadlocals.ThreadLocals',
 'desktopsite.apps.repository.middleware.threadlocals.ThreadLocals')


Template error:
In template /usr/lib/python2.5/site-packages/django/contrib/comments/templates/comments/form.html, error at line 2
   Caught an exception while rendering: Reverse for '<function post_comment at 0x12f1c08>' with arguments '()' and keyword arguments '{}' 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 "/usr/lib/python2.5/site-packages/django/core/handlers/base.py" in get_response
  86.                 response = callback(request, *callback_args, **callback_kwargs)
File "/usr/lib/python2.5/site-packages/django/views/generic/date_based.py" in object_detail
  350.     response = HttpResponse(t.render(c), mimetype=mimetype)
File "/usr/lib/python2.5/site-packages/django/template/__init__.py" in render
  176.         return self.nodelist.render(context)
File "/usr/lib/python2.5/site-packages/django/template/__init__.py" in render
  768.                 bits.append(self.render_node(node, context))
File "/usr/lib/python2.5/site-packages/django/template/debug.py" in render_node
  71.             result = node.render(context)
File "/usr/lib/python2.5/site-packages/django/template/loader_tags.py" in render
  97.         return compiled_parent.render(context)
File "/usr/lib/python2.5/site-packages/django/template/__init__.py" in render
  176.         return self.nodelist.render(context)
File "/usr/lib/python2.5/site-packages/django/template/__init__.py" in render
  768.                 bits.append(self.render_node(node, context))
File "/usr/lib/python2.5/site-packages/django/template/debug.py" in render_node
  71.             result = node.render(context)
File "/usr/lib/python2.5/site-packages/django/template/loader_tags.py" in render
  97.         return compiled_parent.render(context)
File "/usr/lib/python2.5/site-packages/django/template/__init__.py" in render
  176.         return self.nodelist.render(context)
File "/usr/lib/python2.5/site-packages/django/template/__init__.py" in render
  768.                 bits.append(self.render_node(node, context))
File "/usr/lib/python2.5/site-packages/django/template/debug.py" in render_node
  71.             result = node.render(context)
File "/usr/lib/python2.5/site-packages/django/template/loader_tags.py" in render
  97.         return compiled_parent.render(context)
File "/usr/lib/python2.5/site-packages/django/template/__init__.py" in render
  176.         return self.nodelist.render(context)
File "/usr/lib/python2.5/site-packages/django/template/__init__.py" in render
  768.                 bits.append(self.render_node(node, context))
File "/usr/lib/python2.5/site-packages/django/template/debug.py" in render_node
  71.             result = node.render(context)
File "/usr/lib/python2.5/site-packages/django/template/loader_tags.py" in render
  24.         result = self.nodelist.render(context)
File "/usr/lib/python2.5/site-packages/django/template/__init__.py" in render
  768.                 bits.append(self.render_node(node, context))
File "/usr/lib/python2.5/site-packages/django/template/debug.py" in render_node
  71.             result = node.render(context)
File "/usr/lib/python2.5/site-packages/django/template/loader_tags.py" in render
  24.         result = self.nodelist.render(context)
File "/usr/lib/python2.5/site-packages/django/template/__init__.py" in render
  768.                 bits.append(self.render_node(node, context))
File "/usr/lib/python2.5/site-packages/django/template/debug.py" in render_node
  71.             result = node.render(context)
File "/usr/lib/python2.5/site-packages/django/template/loader_tags.py" in render
  24.         result = self.nodelist.render(context)
File "/usr/lib/python2.5/site-packages/django/template/__init__.py" in render
  768.                 bits.append(self.render_node(node, context))
File "/usr/lib/python2.5/site-packages/django/template/debug.py" in render_node
  71.             result = node.render(context)
File "/usr/lib/python2.5/site-packages/django/template/loader_tags.py" in render
  24.         result = self.nodelist.render(context)
File "/usr/lib/python2.5/site-packages/django/template/__init__.py" in render
  768.                 bits.append(self.render_node(node, context))
File "/usr/lib/python2.5/site-packages/django/template/debug.py" in render_node
  71.             result = node.render(context)
File "/usr/lib/python2.5/site-packages/django/template/defaulttags.py" in render
  245.                     return self.nodelist_true.render(context)
File "/usr/lib/python2.5/site-packages/django/template/__init__.py" in render
  768.                 bits.append(self.render_node(node, context))
File "/usr/lib/python2.5/site-packages/django/template/debug.py" in render_node
  71.             result = node.render(context)
File "/usr/lib/python2.5/site-packages/django/contrib/comments/templatetags/comments.py" in render
  159.             formstr = render_to_string(template_search_list, {"form" : self.get_form(context)}, context)
File "/usr/lib/python2.5/site-packages/django/template/loader.py" in render_to_string
  107.     return t.render(context_instance)
File "/usr/lib/python2.5/site-packages/django/template/__init__.py" in render
  176.         return self.nodelist.render(context)
File "/usr/lib/python2.5/site-packages/django/template/__init__.py" in render
  768.                 bits.append(self.render_node(node, context))
File "/usr/lib/python2.5/site-packages/django/template/debug.py" in render_node
  81.             raise wrapped

Exception Type: TemplateSyntaxError at /blog/2008/sep/08/test-entry/
Exception Value: Caught an exception while rendering: Reverse for '<function post_comment at 0x12f1c08>' with arguments '()' and keyword arguments '{}' not found.

Original Traceback (most recent call last):
  File "/usr/lib/python2.5/site-packages/django/template/debug.py", line 71, in render_node
    result = node.render(context)
  File "/usr/lib/python2.5/site-packages/django/template/__init__.py", line 888, in render
    return func(*resolved_vars)
  File "/usr/lib/python2.5/site-packages/django/contrib/comments/templatetags/comments.py", line 246, in comment_form_target
    return comments.get_form_target()
  File "/usr/lib/python2.5/site-packages/django/contrib/comments/__init__.py", line 50, in get_form_target
    return urlresolvers.reverse("django.contrib.comments.views.comments.post_comment")
  File "/usr/lib/python2.5/site-packages/django/core/urlresolvers.py", line 252, in reverse
    *args, **kwargs)))
  File "/usr/lib/python2.5/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 0x12f1c08>' with arguments '()' and keyword arguments '{}' not found.

comment:11 by psychcf, 16 years ago

By the way, I tired everything from deleting the pyc files, to playing with my urls.py file.

comment:12 by Carl Meyer, 16 years ago

Resolution: worksforme
Status: reopenedclosed

Unable to reproduce this on 1.0.

I did have this problem when I first upgraded with "svn up." The culprit was that the old django.contrib.comments had a "urls" directory which was not removed by svn because of the .pyc files in it. The new contrib.comments just has a urls.py file, but the urls directory was masking it. Check your Django source tree under contrib/comments; if there's a urls subdirectory, remove it (you can verify with "svn status" that it shouldn't be there).

comment:13 by psychcf, 16 years ago

That did the trick, thanks

comment:14 by hotani, 16 years ago

After a long absence, this error has reemerged. It alternates between "Reverse..." and "No module named urls." This is what I am getting currently:

Environment:

Request Method: GET
Request URL: http://cmdb-test/helpdesk/68/
Django Version: 1.1 pre-alpha SVN-9109
Python Version: 2.4.3
Installed Applications:
['django.contrib.auth',
 'django.contrib.contenttypes',
 'django.contrib.sessions',
 'django.contrib.sites',
 'django.contrib.admin',
 'django.contrib.admindocs',
 'django.contrib.comments',
 'cmdb.main',
 'cmdb.docs',
 'cmdb.cicada',
 'cmdb.helpdesk',
 'cmdb.inventory',
 'cmdb.conf_eval',
 'cmdb.kudos']
Installed Middleware:
('django.middleware.common.CommonMiddleware',
 'django.contrib.sessions.middleware.SessionMiddleware',
 'django.contrib.auth.middleware.AuthenticationMiddleware',
 'django.middleware.doc.XViewMiddleware')


Template error:
In template /home/web/cmdb/templates/comments/form.html, error at line 4
   Caught an exception while rendering: Reverse for '<function post_comment at 0x2ae96de10848>' with arguments '()' and keyword arguments '{}' not found.
   1 : <p class="text_header">Post a comment</p>


   2 : {% load comments %}


   3 : {% get_comment_form for object as form %}


   4 : <form action=" {% comment_form_target %} " name="cform" method="POST">


   5 : {# built-in hidden spam fields #} 


   6 : {% for field in form %}


   7 :   {% if field.is_hidden %}{{ field }}{% endif %} 


   8 : {% endfor %} 


   9 : 


   10 : {# ------- custom fields ---------- #} 


   11 : {# hidden 'honeypot' field #}


   12 : <p style="display:none;">{{ form.honeypot }}</p>


   13 : 


   14 : {# if user is not logged in, show name and e-mail fields #} 


Traceback:
File "/usr/lib/python2.4/site-packages/django/core/handlers/base.py" in get_response
  86.                 response = callback(request, *callback_args, **callback_kwargs)
File "/home/web/cmdb/helpdesk/views.py" in issue_detail
  410.         template_name = 'helpdesk/detail.html',
File "/usr/lib/python2.4/site-packages/django/views/generic/list_detail.py" in object_detail
  143.     response = HttpResponse(t.render(c), mimetype=mimetype)
File "/usr/lib/python2.4/site-packages/django/template/__init__.py" in render
  176.         return self.nodelist.render(context)
File "/usr/lib/python2.4/site-packages/django/template/__init__.py" in render
  768.                 bits.append(self.render_node(node, context))
File "/usr/lib/python2.4/site-packages/django/template/debug.py" in render_node
  71.             result = node.render(context)
File "/usr/lib/python2.4/site-packages/django/template/loader_tags.py" in render
  97.         return compiled_parent.render(context)
File "/usr/lib/python2.4/site-packages/django/template/__init__.py" in render
  176.         return self.nodelist.render(context)
File "/usr/lib/python2.4/site-packages/django/template/__init__.py" in render
  768.                 bits.append(self.render_node(node, context))
File "/usr/lib/python2.4/site-packages/django/template/debug.py" in render_node
  71.             result = node.render(context)
File "/usr/lib/python2.4/site-packages/django/template/loader_tags.py" in render
  97.         return compiled_parent.render(context)
File "/usr/lib/python2.4/site-packages/django/template/__init__.py" in render
  176.         return self.nodelist.render(context)
File "/usr/lib/python2.4/site-packages/django/template/__init__.py" in render
  768.                 bits.append(self.render_node(node, context))
File "/usr/lib/python2.4/site-packages/django/template/debug.py" in render_node
  71.             result = node.render(context)
File "/usr/lib/python2.4/site-packages/django/template/loader_tags.py" in render
  24.         result = self.nodelist.render(context)
File "/usr/lib/python2.4/site-packages/django/template/__init__.py" in render
  768.                 bits.append(self.render_node(node, context))
File "/usr/lib/python2.4/site-packages/django/template/debug.py" in render_node
  71.             result = node.render(context)
File "/usr/lib/python2.4/site-packages/django/template/loader_tags.py" in render
  111.             return self.template.render(context)
File "/usr/lib/python2.4/site-packages/django/template/__init__.py" in render
  176.         return self.nodelist.render(context)
File "/usr/lib/python2.4/site-packages/django/template/__init__.py" in render
  768.                 bits.append(self.render_node(node, context))
File "/usr/lib/python2.4/site-packages/django/template/debug.py" in render_node
  81.             raise wrapped

Exception Type: TemplateSyntaxError at /helpdesk/68/
Exception Value: Caught an exception while rendering: Reverse for '<function post_comment at 0x2ae96de10848>' with arguments '()' and keyword arguments '{}' not found.

Original Traceback (most recent call last):
  File "/usr/lib/python2.4/site-packages/django/template/debug.py", line 71, in render_node
    result = node.render(context)
  File "/usr/lib/python2.4/site-packages/django/template/__init__.py", line 888, in render
    return func(*resolved_vars)
  File "/usr/lib/python2.4/site-packages/django/contrib/comments/templatetags/comments.py", line 246, in comment_form_target
    return comments.get_form_target()
  File "/usr/lib/python2.4/site-packages/django/contrib/comments/__init__.py", line 50, in get_form_target
    return urlresolvers.reverse("django.contrib.comments.views.comments.post_comment")
  File "/usr/lib/python2.4/site-packages/django/core/urlresolvers.py", line 253, in reverse
    return iri_to_uri(u'%s%s' % (prefix, get_resolver(urlconf).reverse(viewname,
  File "/usr/lib/python2.4/site-packages/django/core/urlresolvers.py", line 242, in reverse
    raise NoReverseMatch("Reverse for '%s' with arguments '%s' and keyword "
NoReverseMatch: Reverse for '<function post_comment at 0x2ae96de10848>' with arguments '()' and keyword arguments '{}' not found.

comment:15 by palewire, 16 years ago

I encountered this problem while porting from 0.96 to 1.0, but was able to fix it by making sure my root urls.py was modified from:

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

to:

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

comment:16 by Russell Keith-Magee, 16 years ago

FYI - this problem was also reported as #9038, which has been fixed on the trunk and 1.0.X branch.

comment:17 by hotani, 16 years ago

I am using svn 9110. 'pyc' files in contrib/comments have been deleted. I've even deleted the entire directory and reloaded it. My url.py files are correct for the new comment system and for the newforms admin. Everything works on dev which is running the django dev server. Yet it fails every time when attempting to load {% comment_form_target %} on two servers running mod_python and apache with the error: "No module named urls."

If I comment out {% comment_form_target %} on these servers, the pages load fine. I've been staring at this error for two days now and am not getting anywhere. Is this bug really fixed?

in reply to:  17 comment:18 by Russell Keith-Magee, 16 years ago

Replying to hotani:

I am using svn 9110. 'pyc' files in contrib/comments have been deleted. I've even deleted the entire directory and reloaded it. My url.py files are correct for the new comment system and for the newforms admin. Everything works on dev which is running the django dev server. Yet it fails every time when attempting to load {% comment_form_target %} on two servers running mod_python and apache with the error: "No module named urls."

The error message that is the cornerstone of this bug is:

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.

If you are getting "No module named urls." errors, there is something else going on here.

If I comment out {% comment_form_target %} on these servers, the pages load fine. I've been staring at this error for two days now and am not getting anywhere. Is this bug really fixed?

[9087] introduced a test case for this specific problem. Prior to [9087], you would get NoReverseMatch errors for those test cases; after [9087], the errors are no longer raised. If you can provide a valid test case that raises NoReverseMatch errors (or any other consistent error message for that matter), please open a new ticket.

comment:19 by hotani, 16 years ago

My problem turned out to be my own stupidity--as is often the case. I had not added a urls.py file for a newish application to version control from the dev server (doy!). Error reporting for this lead me here since I have had this 'comment_form_target' issue in the past. None of the errors were specific to my own code; they were all from django which made my problem difficult to hunt down. The 'comment_form_target' tag was always highlighted in the error report.

Sorry for mucking up this old bug report with my trash!

comment:20 by ashanks, 16 years ago

Resolution: worksforme
Status: closedreopened

It appears that I am having this problem, even on SVN 9234.

I get the following error: Caught an exception while rendering: Reverse for '<function post_comment at 0x134c5b0>' with arguments '()' and keyword arguments '{}' not found.

However, if I remove the line {% render_comment_form for users.userprofile object.id %}, the page works, sans comment form (obviously).

I have meticulously checked and re-checked the setup process, and followed the contrib/comments docs completely.

I have rm'd all old .PYC files in both contrib/comments and in my project's directory.

Please advise. Thanks.

comment:21 by ashanks, 16 years ago

Resolution: worksforme
Status: reopenedclosed

Nevermind. I had a new app without any code, but I had included the app.urls in root urls.py, which I guess Django was giving me this panicky exception when an complete other app was trying to use the comments urls declared in the same file.

Sorry _~

comment:22 by hannnndy <web@…>, 16 years ago

Resolution: worksforme
Status: closedreopened

I have this problem too

Please help:

my setting file Installed apps:

INSTALLED_APPS = (
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.sites',
	'models.news',
	'models.link',
	'models.poll',
	'models.about',
	'models.contact',
	'django.contrib.admin',
	'django.contrib.comments',INSTALLED_APPS = (
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.sites',
	'models.news',
	'models.link',
	'models.poll',
	'models.about',
	'models.contact',
	'django.contrib.admin',
	'django.contrib.comments',

generated error :

TemplateSyntaxError at /news/1/

Caught an exception while rendering: Reverse for '<function post_comment at 0x0175EE30>' 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 0x0175EE30>' with arguments '()' and keyword arguments '{}' not found.

Request Method: GET
Request URL: http://127.0.0.1:8000/news/1/
Exception Type: TemplateSyntaxError
Exception Value:

Caught an exception while rendering: Reverse for '<function post_comment at 0x0175EE30>' 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 0x0175EE30>' with arguments '()' and keyword arguments '{}' not found.

Exception Location: c:\python25\lib\site-packages\django\template\debug.py in render_node, line 81
Python Executable: c:\python25\python.exe
Python Version: 2.5.2
Python Path: ['C:
Documents and Settings
Mohammad
Desktop
witna', 'C:
WINDOWS
system32
python25.zip', 'c:
python25
DLLs', 'c:
python25
lib', 'c:
python25
lib
plat-win', 'c:
python25
lib
lib-tk', 'c:
python25', 'c:
python25
lib
site-packages', 'c:
python25
lib
site-packages
PIL', 'c:
python25
lib
site-packages
wx-2.8-msw-unicode']
Server time: Sun, 26 Oct 2008 13:12:02 +0330
Template error

In template c:\python25\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 0x0175EE30>' with arguments '()' and keyword arguments '{}' 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>

in template file usage:

		<b>{{ news.super_title }}</b>
		<h1>{{ news.title }}</h1>
		<br>
		<em>{{ news.abstract }}</em>
		<br>
		<br>
		{{ news.body|linebreaksbr }}
		<br>
		<br>
		<a href="../"> بازگشت </a>
		{% load comments %}

		{% get_comment_count for news as comment_count %}

		<p>This news has {{ comment_count }} comments.</p>
		
		{% render_comment_form for news.News news.id %}

comment:23 by Carl Meyer, 16 years ago

Resolution: worksforme
Status: reopenedclosed

This is not a bug in Django, it is a configuration issue. Ask for help on the django-users mailing list, not on the ticket tracker.

comment:24 by mandric, 16 years ago

This is a bug in Django since the exception/stacktrace that gets rendered is nearly useless. The problem is farther down in the stack and the templating plumbing is clogging up proper raising of the error. Lately when I get TemplateSyntaxError it is unrelated to the actual problem I see this as an important issue for django.

So after a thorough cleanup of my urls.py and removal of .pyc files this bug disappeared for me. Sure it was a configuration issue but I had to guess where the problem might be so this is a bug in django since the proper exception was not raised. It does not seem related to django.contrib.comments component but there should be a ticket open for this template plumbing issue. It would be nice if we could link to that issue/ticket, if it exists, from this ticket. A bit of testing to make sure the template system raises the correct error when there is an issue in urls.py would be a good start, not sure if that exists already.

comment:25 by polz@…, 16 years ago

adding
(r'comments/', include('django.contrib.comments.urls'),
to urlpatterns in urls.py fixes this issue for me.

comment:26 by call_of_duty_6, 16 years ago

The culprit was that the old django.contrib.comments had a "urls" directory which was not removed by svn because of the .pyc *search files in it.

comment:27 by (none), 16 years ago

milestone: post-1.0

Milestone post-1.0 deleted

comment:28 by usharf, 15 years ago

Just in case someone else finds this bug following a similar error, I've seen this appear when you don't have a matching route in your app's urls.py while referring to the path in a a template.


For example:

in views.py

def show_blog(request, key):
    return object_detail(request, Blog.all(), key)

def add_blog(request):
    return create_object(request, form_class=BlogForm,
        post_save_redirect=reverse('blog.views.show_blog',
                                   kwargs=dict(key='%(key)s')))

in a template:

<p>No blogs found. You can start a <a href="{% url blog.views.add_blog %}">new blog</a>.</p>

If there no route for "add_blog" in your urls.py, you'll see this error.

(r'^create/$', 'add_blog'),
Note: See TracTickets for help on using tickets.
Back to Top