I've just spent the better part of an afternoon dealing with this
issue, then finally figured it out this morning.

Supposing you have this situation (which I saw in a django app that
I've been using lately):

urls.py:
    (r'^viewtest1$', 'testapp.views.viewtest1'),
    (r'^viewtest2$', 'testapp.views.viewtest2'),

testapp/views.py:
    def viewtest1(request):
        return HttpResponse("You've reached view1. It's url is %s" %
view1_url)

    view1_url = reverse(viewtest1)

    def viewtest2(request):
        return HttpResponse("You've reached view2.", mimetype="text/
plain")

When you try to load up http://localhost/viewtest1, you get this
error:

    ViewDoesNotExist at /viewtest1
    Tried viewtest2 in module reverseapp.views. Error was: 'module'
object has no attribute 'viewtest2'

What appears to be happening is that when reverse() is called, it is
presumably importing testapp.views. But, since testapp.views hasn't
been fully loaded at that point, reverse() can't see the any functions
that appear after it in the file, and thus, viewtest2 isn't found.

In my case, I was getting NoReverseMatch errors in my templates for
unrelated views.


So, now that I'm writing this up, I see a little note in the reverse()
documentation which says "don't do it wrong", and I feel like I'm just
complaining now :)

That particular bit of documentation wouldn't have helped my in my
case, since the error originated in a 3rd party app (I was looking
through my own code to see what I did wrong). Anybody else been bitten
by this? Is there a way to make errors like this easier to track down
(especially in templates, where you don't have a stack trace)?


- Seth -

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.

Reply via email to