I keep getting this error: \'str\' object has no attribute \'resolve\'
when trying to accessing the django admin site and I can\'t figure out why. I have apps within
According to excellent answer posted here: http://redsymbol.net/articles/django-attributeerror-str-object-no-attribute-resolve/
There are generally several sources of this error:
You missed 'pattern keyword':
urlpatterns = ('',
(r'^$', direct_to_template, {'template' : 'a.html'}),
# ...
this should be changed to:
urlpatterns = patterns('',
(r'^$', direct_to_template, {'template' : 'a.html'}),
# ...
Note that in Django 1.8+, it's better to use a list of regexes instead of patterns
.
urlpatterns = [
(r'^$', direct_to_template, {'template' : 'a.html'}),
...
]
You missed a comma in some tuple, like:
(r'^hello/$' 'views.whatever')
You commented out some url()s using triple-quotes
You carelessly leave a closing bracket in the wrong place:
(r'^(?P\d{4})/$', 'archive_year', entry_info_dict), 'coltrane_entry_archive_year',
instead of:
(r'^(?P\d{4})/$', 'archive_year', entry_info_dict, 'coltrane_entry_archive_year'),
You set ROOT_URLCONF
to be a list
When migrating from the pattern tuples to a regular list you forgot to remove the empty ''
argument of the pattern.
Please check carefully if you don't have one of this cases in your code.
For me, this caused the problem:
urlpatterns = patterns('',
url(r'^all/$', 'album.views.albums'),
"""
url(r'^create/$', 'album.views.create'),
url(r'^get/(?P<album_id>\d+)/$', 'album.views.album'),
url(r'^like/(?P<album_id>\d+)/$', 'album.views.like_album'),
"""
)
and this solved it:
urlpatterns = patterns('',
url(r'^all/$', 'album.views.albums'),
)
"""
url(r'^create/$', 'album.views.create'),
url(r'^get/(?P<album_id>\d+)/$', 'album.views.album'),
url(r'^like/(?P<album_id>\d+)/$', 'album.views.like_album'),
"""
I saw this possibility in a comment on http://redsymbol.net/articles/django-attributeerror-str-object-no-attribute-resolve/