我收到以下錯誤:ViewDoesNotExist在/
ViewDoesNotExist at/
'<HttpResponse status_code=200, "text/html; charset=utf-8">' is not a callable or a dot-notation path
Request Method: GET
Request URL: http://0.0.0.0:8000/
Django Version: 1.9.7
Exception Type: ViewDoesNotExist
Exception Value:
'<HttpResponse status_code=200, "text/html; charset=utf-8">' is not a callable or a dot-notation path
Exception Location: /Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/django/core/urlresolvers.py in get_callable, line 102
Python Executable: /Library/Frameworks/Python.framework/Versions/3.4/bin/python3
Python Version: 3.4.1
Python Path:
['/Users/mona/interviews/django/learning_site',
'/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/beautifulsoup4-4.3.2-py3.4.egg',
'/Library/Frameworks/Python.framework/Versions/3.4/lib/python34.zip',
'/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4',
'/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/plat-darwin',
'/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/lib-dynload',
'/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages']
Server time: Mon, 20 Jun 2016 13:18:23 +0000
運行此命令:
$ python3 manage.py runserver 0.0.0.0:8000
Performing system checks...
System check identified no issues (0 silenced).
June 20, 2016 - 13:18:16
Django version 1.9.7, using settings 'learning_site.settings'
Starting development server at http://0.0.0.0:8000/
Quit the server with CONTROL-C.
Internal Server Error:/
Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/django/core/handlers/base.py", line 134, in get_response
resolver_match = resolver.resolve(request.path_info)
File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/django/core/urlresolvers.py", line 376, in resolve
sub_match = pattern.resolve(new_path)
File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/django/core/urlresolvers.py", line 248, in resolve
return ResolverMatch(self.callback, args, kwargs, self.name)
File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/django/core/urlresolvers.py", line 255, in callback
self._callback = get_callable(self._callback_str)
File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/functools.py", line 428, in wrapper
result = user_function(*args, **kwds)
File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/django/core/urlresolvers.py", line 102, in get_callable
"'%s' is not a callable or a dot-notation path" % lookup_view
django.core.exceptions.ViewDoesNotExist: '<HttpResponse status_code=200, "text/html; charset=utf-8">' is not a callable or a dot-notation path
[20/Jun/2016 13:18:23] "GET/HTTP/1.1" 500 71836
下面是我在urls.py
文件:
from django.conf.urls import url
from django.contrib import admin
from . import views
urlpatterns = [
url(r'^admin/', admin.site.urls),
url(r'^$', views.hello_world()),
]
和這裏就是我添加到與urls.py相同的目錄下的views.py中:
from django.http import HttpResponse
def hello_world():
return HttpResponse('Helloooo world!')
你能指點我問題的原因以及如何解決它嗎?
你的程序hello_world視圖應該採取單一位置參數:'高清程序hello_world(要求):'在/ 程序hello_world()有0位置參數,但1給出 時改爲你說 –