'str' object has no attribute 'resolve' when access admin site

后端 未结 2 997
独厮守ぢ
独厮守ぢ 2021-01-11 16:57

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

2条回答
  •  臣服心动
    2021-01-11 17:19

    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:

    1. 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'}),
          ...
      ]
      
    2. You missed a comma in some tuple, like:

      (r'^hello/$' 'views.whatever') 
      
    3. You commented out some url()s using triple-quotes

    4. 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'),
      
    5. You set ROOT_URLCONF to be a list

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

提交回复
热议问题