python - 当 "include"ing Django URL 模式时,'function' 对象不可订阅?

标签 python django typeerror

我正在制作一个 Django 网站,我正在看一个教程 http://youtube.com ,我遇到了问题。这是我的 urls.py 脚本:

from django.conf.urls import patterns, include, url

# Uncomment the next two lines to enable the admin:
# from django.contrib import admin
# admin.autodiscover()

urlpatterns = patterns('',
    (r'^', include['FirstBlog.apps.homepage.urls']),
    # Examples:
    # url(r'^$', 'FirstBlog.views.home', name='home'),
    # url(r'^FirstBlog/', include('FirstBlog.foo.urls')),

    # Uncomment the admin/doc line below to enable admin documentation:
    # url(r'^admin/doc/', include('django.contrib.admindocs.urls')),

    # Uncomment the next line to enable the admin:
    # url(r'^admin/', include(admin.site.urls)),
)

我的输出:

TypeError at /
'function' object is not subscriptable
Request Method: GET
Request URL:    http://127.0.0.1:8000/
Django Version: 1.4
Exception Type: TypeError
Exception Value:    
'function' object is not subscriptable
Exception Location: /Users/thor/Sites/FirstBlog/FirstBlog/urls.py in <module>, line 8
Python Executable:  /usr/bin/python
Python Version: 2.7.1
Python Path:    
['/Users/thor/Sites/FirstBlog',
 '/Library/Python/2.7/site-packages/MySQL_python-1.2.3-py2.7-macosx-10.7-intel.egg',
 '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python27.zip',
 '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7',
 '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-darwin',
 '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac',
 '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac/lib-scriptpackages',
 '/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python',
 '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-tk',
 '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-old',
 '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-dynload',
 '/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/PyObjC',
 '/Library/Python/2.7/site-packages']
Server time:    Wed, 2 May 2012 17:42:04 -0500

请帮忙?

此外,如果您有我可以遵循的好的教程,请将其链接给我!此外,我更愿意将 Mamp Pro 用于数据库。帮助 n00b?

最佳答案

include 是一个函数;你正在订阅它,就好像它是一个列表。

例如:

apples = [ 'Granny Smith', 'Russet' ]
red_apple = apples[1]    # <-- Subscripting a list

因为函数不能被下标,所以你得到了你发布的错误。但是,从注释示例中可以看出,您应该使用 () 语法调用函数:

(r'^', include('FirstBlog.apps.homepage.urls'))
#             ^                              ^

关于python - 当 "include"ing Django URL 模式时,'function' 对象不可订阅?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10422822/

相关文章:

python - 重定向到引用页面的最佳方式

python - 是否可以在 background-image 属性中使用从 context_dict 传下来的图像? Django

python - TypeError:强制转换为 Unicode:需要字符串或缓冲区

ionic-framework - ionic 服务抛出类型错误 : Appscripts. 服务

python - 制作自定义 Keras 层时无法使用未知的输入 Dims(批量大小)

python,打开的文件会被关闭吗?

python - 获取 TypeError : can't pickle _thread. RLock 对象

python - 如何在 Django 1.8 中多次保存同一个表单?

python - 获取字段查询值的元组

javascript - 未捕获的类型错误 : Cannot read property 'top' of undefined