我正在做这本书中的教程,在 24 小时内自学 Django,在第 1 部分的第 4 小时,我陷入了这个错误。
Traceback (most recent call last):
File "C:\Python25\lib\site-packages\django\core\servers\basehttp.py", line 278, in run
self.result = application(self.environ, self.start_response)
File "C:\Python25\lib\site-packages\django\core\servers\basehttp.py", line 635, in __call__
return self.application(environ, start_response)
File "C:\Python25\lib\site-packages\django\core\handlers\wsgi.py", line 239, in __call__
response = self.get_response(request)
File "C:\Python25\lib\site-packages\django\core\handlers\base.py", line 67, in get_response
response = middleware_method(request)
File "C:\Python25\Lib\site-packages\django\middleware\common.py", line 56, in process_request
if (not _is_valid_path(request.path_info) and
File "C:\Python25\Lib\site-packages\django\middleware\common.py", line 142, in _is_valid_path
urlresolvers.resolve(path)
File "C:\Python25\Lib\site-packages\django\core\urlresolvers.py", line 254, in resolve
return get_resolver(urlconf).resolve(path)
File "C:\Python25\Lib\site-packages\django\core\urlresolvers.py", line 181, in resolve
for pattern in self.url_patterns:
File "C:\Python25\Lib\site-packages\django\core\urlresolvers.py", line 205, in _get_url_patterns
patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module)
File "C:\Python25\Lib\site-packages\django\core\urlresolvers.py", line 200, in _get_urlconf_module
self._urlconf_module = __import__(self.urlconf_name, {}, {}, [''])
File "c:\projects\iFriends\..\iFriends\urls.py", line 17, in <module>
(r'^admin/', include('django.contribute.admin.urls'))
TypeError: 'tuple' object is not callable
谁能帮帮我..
网址.py
from django.conf.urls.defaults import *
####Uncomment the next two lines to enable the admin:
#### from django.contrib import admin
#### admin.autodiscover()
urlpatterns = patterns('',
(r'^People/$', 'iFriends.People.views.index') ,
(r'^admin/', include('django.contrib.admin.urls')),
# Example:
# (r'^iFriends/', include('iFriends.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:
)
请您参考如下方法:
您以某种方式将一些函数设置为一个元组。请编辑问题并粘贴您的 urls.py 代码,以便我们指出错误。
我可以尝试大胆猜测:
File "c:\projects\iFriends\..\iFriends\urls.py", line 17, in <module>
(r'^admin/', include('django.contribute.admin.urls'))
这不知何故告诉我你在第 16 行漏掉了一个逗号,所以:
16. (r'^/', 'some_stuff....') # <-- missed comma here
17. (r'^admin/', include('django.contribute.admin.urls'))
只需输入逗号即可。如果不是这样,我会把我的 Crystal 球送去维修。粘贴代码。
编辑
您似乎粘贴了 urls.py 作为答案。请编辑问题并将 urls.py 粘贴到那里。
不管怎样,错误已经改变了。你做了什么?在这个新错误中,urls.py 不再找到,所以也许您已经重命名了它?您是否更改了运行应用程序的方式?
您粘贴的文件不是正在运行的文件。你在粘贴 url.py 而 django 正在读取 urls.py 吗?错误中的代码与您粘贴的代码不匹配!请粘贴正确的文件,即给出错误的文件,否则我们无能为力。
