2
votes

I'm trying to reverse a named url called blog-home but no matter what I try it always throws an AttributeError with the description 'NoneType' object has no attribute 'rindex'.

I've tried reverse("blog-home"), reverse("blogengine:blog-home") and even reverse("admin:index") and reverse(resolve("/admin/")) just to test if my code was the problem.

The traceback:

Traceback (most recent call last):
  File "", line 1, in 
  File "C:\Python27\lib\site-packages\django-1.3-py2.7.egg\django\core\urlresolvers.py", line 368, in reverse
    app_list = resolver.app_dict[ns]
  File "C:\Python27\lib\site-packages\django-1.3-py2.7.egg\django\core\urlresolvers.py", line 241, in _get_app_dict
    self._populate()
  File "C:\Python27\lib\site-packages\django-1.3-py2.7.egg\django\core\urlresolvers.py", line 208, in _populate
    for name in pattern.reverse_dict:
  File "C:\Python27\lib\site-packages\django-1.3-py2.7.egg\django\core\urlresolvers.py", line 229, in _get_reverse_dict
    self._populate()
  File "C:\Python27\lib\site-packages\django-1.3-py2.7.egg\django\core\urlresolvers.py", line 220, in _populate
    lookups.appendlist(pattern.callback, (bits, p_pattern))
  File "C:\Python27\lib\site-packages\django-1.3-py2.7.egg\django\core\urlresolvers.py", line 169, in _get_callback
    mod_name, func_name = get_mod_func(self._callback_str)
  File "C:\Python27\lib\site-packages\django-1.3-py2.7.egg\django\core\urlresolvers.py", line 113, in get_mod_func
    dot = callback.rindex('.')
AttributeError: 'NoneType' object has no attribute 'rindex'

I'm really not sure about why this happens, especially as I've used reverse successfully on other projects with the same version of Python and Django and I haven't found anything about this error anywhere else so far.

My urls.py:

from django.conf.urls.defaults import patterns, include, url

from . import views
from .models import Post, Tag

from django.views.generic import DetailView, ListView

urlpatterns = patterns('',
    url(r'^$', ListView.as_view(queryset=Post.objects.order_by('-pub_date')), name="blog-home"),
    url(r'^yadda/$', None)
)

Which is imported by this urls.py:

from django.conf.urls.defaults import patterns, include, url

from django.contrib import admin
admin.autodiscover()

from django.contrib.sitemaps import FlatPageSitemap

class FlatPageSitemap(FlatPageSitemap):
    changefreq = "daily"

sitemaps = {
    'flatpages': FlatPageSitemap,
}

import django.contrib.sitemaps.views
from . import blogengine

urlpatterns = patterns('',
    url(r'^', include(blogengine.urls)),
    url(r'^sitemap\.xml', django.contrib.sitemaps.views.sitemap, {'sitemaps': sitemaps}),
    url(r'^admin/doc/', include('django.contrib.admindocs.urls')),
    url(r'^admin/', include(admin.site.urls)),
)

I was originally intending to use it from the Django templating system with the url tag ({% url blog-home %}).

1
could you show us your urls.py containing blog-home and the code you are using where the reverse method is called. Apparently, something is null.Cyril N.
I'm just invoking reverse from a manage.py shell interactive shell for now, while debugging.Teo Klestrup Röijezon
The point @cx42net is making is that there are many things that affect reverse. It could be choking on something in urls.py or in one of your views. There's nothing wrong with how you're calling reverse, so the error must be somewhere else in your code. We need more context to help you further.Chris Pratt
Okay, @chrisdpratt, but I'm not really sure about what kind of context it is that you want.Teo Klestrup Röijezon

1 Answers

4
votes

Don't do that:

url(r'^yadda/$', None)

If you specify an URL in the conf, it must be bound to something. If you don't want to bind it, don't specify it.