Django: AttributeError: 'str' object has no attribute 'resolve'

Here is today's obscure error message and its solutions.

Say you are working on a Django project, using its development web server, and you get this exception when you try to load a page in the browser:

AttributeError: 'str' object has no attribute 'resolve'

1. 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.

Actually patterns Deprecated since 1.8.

urlpatterns = [

    (r'^$', direct_to_template, {'template' : 'a.html'}),



See the difference? In the first one, I'm incorrectly assigning urlpatterns to be a tuple. In the second, I'm correctly using the django.conf.urls.defaults.patterns function.


2. Miessed comma in some tuple, like:

(r'^hello/$' 'views.whatever') 


3. Commented out some url()s using triple-quotes

urlpatterns = [

    url(r'^admin/', include(,

    url(r'^cart/', include('cart.urls', namespace='cart')),

    url(r'^payment/', include('payment.urls', namespace='payment')),

    url(r'^orders/', include('orders.urls', namespace='orders')),

    url(r'^paypal/', include('paypal.standard.ipn.urls')),

    url(r'^', include('shop.urls', namespace='shop')),

"""    start REST urls

    url('^.*$', IndexView.as_view(), name='index'),

    url(r'^api/v1/', include(router.urls)),

       end REST urls



4. Carelessly leaved 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'),

5. ROOT_URLCONF set to be a list


======= >>>>>>> master

+30 211 790 2526

Find me