Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/django/19.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Django ';str';对象没有属性';解决';何时访问管理站点_Django_Admin - Fatal编程技术网

Django ';str';对象没有属性';解决';何时访问管理站点

Django ';str';对象没有属性';解决';何时访问管理站点,django,admin,Django,Admin,我不断地发现这个错误: “str”对象没有属性“resolve” 当我试图访问django管理站点时,我无法理解 为什么? 我的项目中有一些应用程序有自己的admin.py文件。 这会导致它吗? 这是我的URL.py: from django.conf.urls.defaults import * import settings from django.contrib.auth.views import login, logout from views import index, simple,

我不断地发现这个错误: “str”对象没有属性“resolve”

当我试图访问django管理站点时,我无法理解 为什么? 我的项目中有一些应用程序有自己的admin.py文件。 这会导致它吗? 这是我的URL.py:

from django.conf.urls.defaults import *
import settings
from django.contrib.auth.views import login, logout
from views import index, simple, complex
from django.views.generic.simple import direct_to_template

# Uncomment the next two lines to enable the admin:
from django.contrib import admin
admin.autodiscover()
urlpatterns = patterns('',
    # Example:
    # (r'^django_jchat/', include('django_jchat.foo.urls')),
    # Uncomment the admin/doc line below and add 'django.contrib.admindocs'
    # to INSTALLED_APPS to enable admin documentation:
     (r'^admin/doc/', include('django.contrib.admindocs.urls')),
    # Uncomment the next line to enable the admin:
    (r'^admin/', include(admin.site.urls)), 

以下是追溯:

'str' object has no attribute 'resolve'
Request Method:         GET
Django Version:         1.3
Exception Type:         AttributeError
Exception Value:
'str' object has no attribute 'resolve'
Exception Location:     /home/dockedin/webapps/peebletalk/lib/python2.7/
django/core/urlresolvers.py in resolve, line 252
Python Executable:      /usr/local/bin/python
Python Version:         2.7.1
Python Path:
['/home/dockedin/webapps/peebletalk',
 '/home/dockedin/webapps/peebletalk/lib/python2.7',
 '/home/dockedin/lib/python2.7',
 '/usr/local/lib/python27.zip',
 '/usr/local/lib/python2.7',
 '/usr/local/lib/python2.7/plat-linux2',
 '/usr/local/lib/python2.7/lib-tk',
 '/usr/local/lib/python2.7/lib-old',
 '/usr/local/lib/python2.7/lib-dynload',
 '/usr/local/lib/python2.7/site-packages',
 '/usr/local/lib/python2.7/site-packages/PIL']
Server time:    Wed, 10 Aug 2011 15:24:55 -0400
Traceback Switch to copy-and-paste view
    /home/dockedin/webapps/peebletalk/lib/python2.7/django/core/
handlers/base.py in get_response
                            response = middleware_method(request)
        ...
    ▶ Local vars
    /home/dockedin/webapps/peebletalk/lib/python2.7/django/middleware/
common.py in process_request
                    if (not _is_valid_path(request.path_info, urlconf)
and
          ...
    ▶ Local vars
    /home/dockedin/webapps/peebletalk/lib/python2.7/django/middleware/
common.py in _is_valid_path
                urlresolvers.resolve(path, urlconf)

        ...
    ▶ Local vars
    /home/dockedin/webapps/peebletalk/lib/python2.7/django/core/
urlresolvers.py in resolve
            return get_resolver(urlconf).resolve(path)
            ...
    ▶ Local vars
    /home/dockedin/webapps/peebletalk/lib/python2.7/django/core/
urlresolvers.py in resolve
            def resolve(self, path):
                tried = []
                match = self.regex.search(path)
                if match:
                    new_path = path[match.end():]
                    for pattern in self.url_patterns:
                        try:
                            sub_match = pattern.resolve(new_path)
        ...
                        except Resolver404, e:
                            sub_tried = e.args[0].get('tried')
                            if sub_tried is not None:
                                tried.extend([[pattern] + t for t in
sub_tried])
                            else:
                                tried.append([pattern]) 

根据这里发布的优秀答案:

此错误通常有几个来源:

  • 你错过了“模式关键字”:

    urlpatterns = ('',
    (r'^$', direct_to_template, {'template' : 'a.html'}),
    # ...
    
    这应改为:

    urlpatterns = patterns('',
    (r'^$', direct_to_template, {'template' : 'a.html'}),
    # ...
    
    请注意,在Django 1.8+中,最好使用正则表达式列表,而不是
    模式

    urlpatterns = [
        (r'^$', direct_to_template, {'template' : 'a.html'}),
        ...
    ]
    
  • 在某个元组中缺少逗号,例如:

    (r'^hello/$' 'views.whatever') 
    
  • 您使用三重引号注释掉了一些url()

  • 您不小心将闭合支架放在了错误的位置:

    (r'^(?P\d{4})/$', 'archive_year', entry_info_dict), 'coltrane_entry_archive_year',
    
    而不是:

    (r'^(?P\d{4})/$', 'archive_year', entry_info_dict, 'coltrane_entry_archive_year'),
    
  • 您将
    ROOT\u URLCONF
    设置为一个列表

  • 从模式元组迁移到常规列表时,您忘记删除模式的空
    '
    参数


  • 如果您的代码中没有这种情况,请仔细检查。

    对于我来说,这导致了问题:

    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'),
    """
    )
    
    urlpatterns=patterns(“”,
    url(r“^all/$”、“album.views.albums”),
    """
    url(r“^create/$”、“album.views.create”),
    
    url(r'^get/(?P

    )您可能希望在此处实际包含一个答案,而不仅仅是链接到外部网站。这意味着访问者不必去其他任何地方,并且可以防止您的答案在该网站出现故障/消失时失效。回答很好,这解决了我的问题(由于在列表中引用了三个项目)天哪!当从元组迁移到列表时,您使用三重引号注释掉了一些url(),如果没有注释,请删除
    模式的空
    '
    参数。
    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'),
    """