Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/django/24.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
Python 呈现时捕获类型错误:不可损坏类型:';dict';_Python_Django - Fatal编程技术网

Python 呈现时捕获类型错误:不可损坏类型:';dict';

Python 呈现时捕获类型错误:不可损坏类型:';dict';,python,django,Python,Django,我正在努力学习《Django实用项目》这本书,但这本书不管用。到目前为止,您可以找到我的代码(没有“Link”类。我刚刚添加了get_absolute_url条目类,在尝试访问管理页面时,突然出现了一个“catch TypeError while rendering:unhabable type:'dict'”错误。我从未修改过错误中显示的文件中的任何内容:(。我该怎么办 编辑:添加以下内容后出现错误: def get_absolute_url(self): return ('coltr

我正在努力学习《Django实用项目》这本书,但这本书不管用。到目前为止,您可以找到我的代码(没有“Link”类。我刚刚添加了get_absolute_url条目类,在尝试访问管理页面时,突然出现了一个“catch TypeError while rendering:unhabable type:'dict'”错误。我从未修改过错误中显示的文件中的任何内容:(。我该怎么办

编辑:添加以下内容后出现错误:

def get_absolute_url(self):
    return ('coltrane_entry_detail', (), { 'year': self.pub_date.strftime("%Y"),
                                           'month': self.pub_date.strftime("%b").lower(),
                                           'day': self.pub_date.strftime("%d"),
                                           'slug': self.slug })
get_absolute_url = models.permalink(get_absolute_url)
这是URL.py中的内容:

urlpatterns = patterns('django.views.generic.date_based',
    (r'^$', 'archive_index', entry_info_dict, 'coltrane_entry_archive_index'),
    (r'^(?P<year>\d{4})/$', 'archive_year', entry_info_dict, 'coltrane_entry_archive_year'),
    (r'^(?P<year>\d{4})/(?P<month>\w{3})/$', 'archive_month', entry_info_dict, 'coltrane_entry_archive_month'),
    (r'^(?P<year>\d{4})/(?P<month>\w{3})/(?P<day>\d{2})/$', 'archive_day', entry_info_dict, 'coltrane_entry_archive_day'),
    (r'^(?P<year>\d{4})/(?P<month>\w{3})/(?P<day>\d{2})/?(?P<slug>[-\w]+)/$', 'object_detail', entry_info_dict, 'coltrane_entry_detail'),
)
urlpatterns=patterns('django.views.generic.date_-based',
(r'^$'、'存档索引'、条目信息记录'、'coltrane条目存档索引'),
(r'^(?P\d{4})/$,'档案年',条目信息记录,'档案年',
(r’^(?P\d{4})/(?P\w{3})/$,“存档月”,条目信息目录,“coltrane\u条目存档月”),
(r'^(?P\d{4})/(?P\w{3})/(?P\d{2})/$”,“存档日”,条目信息记录,“coltrane\u条目存档日”),
(r'^(?P\d{4})/(?P\w{3})/(?P\d{2})/?(?P[-\w]+)/$','object_detail',entry_info dict',coltrane_entry_detail'),
)

很抱歉,您的代码目前未加载

据我所知,您可能正在尝试使用
dict
实例作为
dict
键。 例如,您不能这样做:

a = {'1' : 'one'}
b = {a : 'two'}

很抱歉,您的代码目前未加载

据我所知,您可能正在尝试使用
dict
实例作为
dict
键。 例如,您不能这样做:

a = {'1' : 'one'}
b = {a : 'two'}

你能给我看一下你的URLconf中的哪一行,其中命名了
coltrane\u entry\u detail
url吗?至少这表明错误可能是由错误配置的url模式引起的,如果你刚刚为你的模型添加了
get\u absolute\u url
方法,我猜你可能也刚刚添加了它所指的命名视图?

你能帮我看看吗请告诉我您的URLconf中命名了
coltrane\u entry\u detail
url的那一行?至少表明错误可能是由错误配置的url模式引起的,如果您刚刚为您的模型添加了
get\u absolute\u url
方法,我猜您可能也刚刚添加了它所指的命名视图?

您有django e吗使用pip和VirtualEnvironment设置?您的项目具有以下依赖项:

markdown==2.0.3
django-tagging==0.3.1
我已经在您的项目级别将上述内容放在名为
requirements.txt
的文件中。一旦您安装了pip、virtualenv并为该项目创建了一个独特的环境,您就可以按照以下方式安装上述内容:

pip install -r requirements.txt
在上一次设置之后,您需要在
设置的
已安装的应用程序中添加
标记
。py

INSTALLED_APPS = (
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.sites',
    'django.contrib.admin',
    'django.contrib.flatpages',
    'cms.search',
    'coltrane',
    'tagging',
)

删除您的
cms.db
数据库文件并运行
python manage.py syncndb
。您需要为超级用户提供用户名和密码。我这边的代码运行正常,我可以访问管理员。

您是否使用pip和VirtualEnvironment设置了django环境?您的项目具有以下依赖项:

markdown==2.0.3
django-tagging==0.3.1
我已经在您的项目级别将上述内容放在名为
requirements.txt
的文件中。一旦您安装了pip、virtualenv并为该项目创建了一个独特的环境,您就可以按照以下方式安装上述内容:

pip install -r requirements.txt
在上一次设置之后,您需要在
设置的
已安装的应用程序中添加
标记
。py

INSTALLED_APPS = (
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.sites',
    'django.contrib.admin',
    'django.contrib.flatpages',
    'cms.search',
    'coltrane',
    'tagging',
)

删除你的
cms.db
数据库文件并运行
python manage.py sycndb
。你需要为超级用户提供用户名和密码。我这边的代码运行良好,我可以访问管理员。

有时我们使用HTTPResponse实例而不是render方法时会出现这种情况


例如: 就我而言

返回HttpResponse(请求'doctor\u list.html',{'list':doctor\u list})

使用

返回渲染(请求'doctor\u list.html',{'list':doctor\u list})

当我们使用HTTPResponse实例而不是render方法时,有时会出现这种情况


例如: 就我而言

返回HttpResponse(请求'doctor\u list.html',{'list':doctor\u list})

使用

返回渲染(请求'doctor\u list.html',{'list':doctor\u list})

在我的原始问题中添加了它。在我的原始问题中添加了它。