[英]localhost: A server error occurred. Please contact the administrator
我正在学习在https://www.dj4e.com/的帮助下使用 Django 运行本地主机。 我目前正在尝试使用以下命令运行本地服务器:
python manage.py runserver
当我运行它时,终端中给出的 output 如下:
Watching for file changes with StatReloader
Performing system checks...
System check identified no issues (0 silenced).
February 26, 2022 - 15:21:09
Django version 3.2.5, using settings 'mysite.settings'
Starting development server at http://127.0.0.1:8000/
Quit the server with CTRL-BREAK.
我点击进入127.0.0.1:8000,但是服务器输出标题中的错误, A server error occurred。 请联系管理员。 我的终端也输出以下错误:
Traceback (most recent call last):
File "C:\Python\Python310\lib\wsgiref\handlers.py", line 137, in run
self.result = application(self.environ, self.start_response)
File "C:\Python\Python310\lib\site-packages\django\contrib\staticfiles\handlers.py", line 76, in __call__
return self.application(environ, start_response)
File "C:\Python\Python310\lib\site-packages\django\contrib\staticfiles\handlers.py", line 76, in __call__
return self.application(environ, start_response)
TypeError: get_wsgi_application() takes 0 positional arguments but 2 were given
[26/Feb/2022 15:13:30] "GET / HTTP/1.1" 500 59
Traceback (most recent call last):
File "C:\Python\Python310\lib\wsgiref\handlers.py", line 137, in run
self.result = application(self.environ, self.start_response)
File "C:\Python\Python310\lib\site-packages\django\contrib\staticfiles\handlers.py", line 76, in __call__
return self.application(environ, start_response)
File "C:\Python\Python310\lib\site-packages\django\contrib\staticfiles\handlers.py", line 76, in __call__
return self.application(environ, start_response)
TypeError: get_wsgi_application() takes 0 positional arguments but 2 were given
[26/Feb/2022 15:13:30] "GET /favicon.ico HTTP/1.1" 500 59
C:\Users\afrid\Desktop\Coding Projects\Django\mysite\mysite\settings.py changed, reloading.
Performing system checks...
System check identified no issues (0 silenced).
February 26, 2022 - 15:13:55
Django version 3.2.5, using settings 'mysite.settings'
Starting development server at http://127.0.0.1:8000/
Quit the server with CTRL-BREAK.
Traceback (most recent call last):
File "C:\Python\Python310\lib\wsgiref\handlers.py", line 137, in run
self.result = application(self.environ, self.start_response)
File "C:\Python\Python310\lib\site-packages\django\contrib\staticfiles\handlers.py", line 76, in __call__
return self.application(environ, start_response)
TypeError: get_wsgi_application() takes 0 positional arguments but 2 were given
[26/Feb/2022 15:14:00] "GET / HTTP/1.1" 500 59
Traceback (most recent call last):
File "C:\Python\Python310\lib\wsgiref\handlers.py", line 137, in run
self.result = application(self.environ, self.start_response)
File "C:\Python\Python310\lib\site-packages\django\contrib\staticfiles\handlers.py", line 76, in __call__
return self.application(environ, start_response)
TypeError: get_wsgi_application() takes 0 positional arguments but 2 were given
[26/Feb/2022 15:14:00] "GET /favicon.ico HTTP/1.1" 500 59
Traceback (most recent call last):
File "C:\Users\afrid\Desktop\Coding Projects\django\mysite\manage.py", line 22, in <module>
main()
File "C:\Users\afrid\Desktop\Coding Projects\django\mysite\manage.py", line 18, in main
execute_from_command_line(sys.argv)
File "C:\Python\Python310\lib\site-packages\django\core\management\__init__.py", line 419, in execute_from_command_line
utility.execute()
File "C:\Python\Python310\lib\site-packages\django\core\management\__init__.py", line 363, in execute
settings.INSTALLED_APPS
File "C:\Python\Python310\lib\site-packages\django\conf\__init__.py", line 82, in __getattr__
self._setup(name)
File "C:\Python\Python310\lib\site-packages\django\conf\__init__.py", line 69, in _setup
self._wrapped = Settings(settings_module)
File "C:\Python\Python310\lib\site-packages\django\conf\__init__.py", line 170, in __init__
mod = importlib.import_module(self.SETTINGS_MODULE)
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1050, in _gcd_import
File "<frozen importlib._bootstrap>", line 1006, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 688, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 883, in exec_module
File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
File "C:\Users\afrid\Desktop\Coding Projects\django\mysite\mysite\settings.py", line 26, in <module>
DEBUG = FALSE
NameError: name 'FALSE' is not defined. Did you mean: 'False'?
PS C:\Users\afrid\Desktop\Coding Projects\django\mysite> python manage.py runserverpython manage.py runserver
Unknown command: 'runserverpython'. Did you mean runserver?
Type 'manage.py help' for usage.
PS C:\Users\afrid\Desktop\Coding Projects\django\mysite> python manage.py runserver
Watching for file changes with StatReloader
Performing system checks...
System check identified no issues (0 silenced).
February 26, 2022 - 15:14:24
Django version 3.2.5, using settings 'mysite.settings'
Starting development server at http://127.0.0.1:8000/
Quit the server with CTRL-BREAK.
Traceback (most recent call last):
File "C:\Python\Python310\lib\wsgiref\handlers.py", line 137, in run
self.result = application(self.environ, self.start_response)
File "C:\Python\Python310\lib\site-packages\django\contrib\staticfiles\handlers.py", line 76, in __call__
return self.application(environ, start_response)
File "C:\Python\Python310\lib\site-packages\django\contrib\staticfiles\handlers.py", line 76, in __call__
return self.application(environ, start_response)
TypeError: get_wsgi_application() takes 0 positional arguments but 2 were given
[26/Feb/2022 15:14:29] "GET / HTTP/1.1" 500 59
Traceback (most recent call last):
File "C:\Python\Python310\lib\wsgiref\handlers.py", line 137, in run
self.result = application(self.environ, self.start_response)
File "C:\Python\Python310\lib\site-packages\django\contrib\staticfiles\handlers.py", line 76, in __call__
return self.application(environ, start_response)
File "C:\Python\Python310\lib\site-packages\django\contrib\staticfiles\handlers.py", line 76, in __call__
return self.application(environ, start_response)
TypeError: get_wsgi_application() takes 0 positional arguments but 2 were given
[26/Feb/2022 15:14:29] "GET /favicon.ico HTTP/1.1" 500 59
C:\Users\afrid\Desktop\Coding Projects\Django\mysite\mysite\settings.py changed, reloading.
Watching for file changes with StatReloader
Performing system checks...
System check identified no issues (0 silenced).
February 26, 2022 - 15:15:47
Django version 3.2.5, using settings 'mysite.settings'
Starting development server at http://127.0.0.1:8000/
Quit the server with CTRL-BREAK.
Traceback (most recent call last):
File "C:\Python\Python310\lib\wsgiref\handlers.py", line 137, in run
self.result = application(self.environ, self.start_response)
File "C:\Python\Python310\lib\site-packages\django\contrib\staticfiles\handlers.py", line 76, in __call__
return self.application(environ, start_response)
File "C:\Python\Python310\lib\site-packages\django\contrib\staticfiles\handlers.py", line 76, in __call__
return self.application(environ, start_response)
TypeError: get_wsgi_application() takes 0 positional arguments but 2 were given
[26/Feb/2022 15:15:49] "GET / HTTP/1.1" 500 59
Traceback (most recent call last):
File "C:\Python\Python310\lib\wsgiref\handlers.py", line 137, in run
self.result = application(self.environ, self.start_response)
File "C:\Python\Python310\lib\site-packages\django\contrib\staticfiles\handlers.py", line 76, in __call__
return self.application(environ, start_response)
File "C:\Python\Python310\lib\site-packages\django\contrib\staticfiles\handlers.py", line 76, in __call__
return self.application(environ, start_response)
TypeError: get_wsgi_application() takes 0 positional arguments but 2 were given
[26/Feb/2022 15:15:50] "GET /favicon.ico HTTP/1.1" 500 59
C:\Users\afrid\Desktop\Coding Projects\Django\mysite\mysite\settings.py changed, reloading.
Watching for file changes with StatReloader
Performing system checks...
System check identified no issues (0 silenced).
February 26, 2022 - 15:16:04
Django version 3.2.5, using settings 'mysite.settings'
Starting development server at http://127.0.0.1:8000/
Quit the server with CTRL-BREAK.
Traceback (most recent call last):
File "C:\Python\Python310\lib\wsgiref\handlers.py", line 137, in run
self.result = application(self.environ, self.start_response)
File "C:\Python\Python310\lib\site-packages\django\contrib\staticfiles\handlers.py", line 76, in __call__
return self.application(environ, start_response)
File "C:\Python\Python310\lib\site-packages\django\contrib\staticfiles\handlers.py", line 76, in __call__
return self.application(environ, start_response)
[26/Feb/2022 15:16:07] "GET / HTTP/1.1" 500 59
Traceback (most recent call last):
File "C:\Python\Python310\lib\wsgiref\handlers.py", line 137, in run
self.result = application(self.environ, self.start_response)
File "C:\Python\Python310\lib\site-packages\django\contrib\staticfiles\handlers.py", line 76, in __call__
return self.application(environ, start_response)
File "C:\Python\Python310\lib\site-packages\django\contrib\staticfiles\handlers.py", line 76, in __call__
return self.application(environ, start_response)
TypeError: get_wsgi_application() takes 0 positional arguments but 2 were given
[26/Feb/2022 15:16:07] "GET /favicon.ico HTTP/1.1" 500 59
PS C:\Users\afrid\Desktop\Coding Projects\django\mysite> python manage.py runserver
Watching for file changes with StatReloader
Performing system checks...
System check identified no issues (0 silenced).
February 26, 2022 - 15:21:09
Django version 3.2.5, using settings 'mysite.settings'
Starting development server at http://127.0.0.1:8000/
Quit the server with CTRL-BREAK.
Traceback (most recent call last):
File "C:\Python\Python310\lib\wsgiref\handlers.py", line 137, in run
self.result = application(self.environ, self.start_response)
File "C:\Python\Python310\lib\site-packages\django\contrib\staticfiles\handlers.py", line 76, in __call__
return self.application(environ, start_response)
File "C:\Python\Python310\lib\site-packages\django\contrib\staticfiles\handlers.py", line 76, in __call__
return self.application(environ, start_response)
TypeError: get_wsgi_application() takes 0 positional arguments but 2 were given
[26/Feb/2022 15:22:49] "GET / HTTP/1.1" 500 59
Traceback (most recent call last):
File "C:\Python\Python310\lib\wsgiref\handlers.py", line 137, in run
self.result = application(self.environ, self.start_response)
File "C:\Python\Python310\lib\site-packages\django\contrib\staticfiles\handlers.py", line 76, in __call__
return self.application(environ, start_response)
File "C:\Python\Python310\lib\site-packages\django\contrib\staticfiles\handlers.py", line 76, in __call__
return self.application(environ, start_response)
TypeError: get_wsgi_application() takes 0 positional arguments but 2 were given
[26/Feb/2022 15:22:49] "GET /favicon.ico HTTP/1.1" 500 59
我不完全确定问题出在哪里,我已经运行了所有迁移并且应该已经设置了管理员用户。
任何帮助将不胜感激。
请查看 wsgi.py 文件...错误消息看起来像是您不小心修改了 get_wsgi_application 行:
在 wsgi.py 中:
# correct:
application = get_wsgi_application()
# in your case most certainly wrong:
application = get_wsgi_application
背后的一些解释:
f = my_function # my_function is not called but stored in f
f = my_function() # my_function is called and the return value stored in f
# note: if my_thing is an object instantiated from a class
-> my_thing() will call the my_thing.__call()__ method
错误消息显示调用“self.application(environ, start_response)”,这是对 Django 应用程序的 WSGI 标准相关调用。 这个调用应该 go 到一个可以处理它的对象/函数,但是它转到 get_wsgi_application() -> 类型错误。
File "C:\Python\Python310\lib\site-packages\django\contrib\staticfiles\handlers.py", line 76, in __call__
return self.application(environ, start_response)
TypeError: get_wsgi_application() takes 0 positional arguments but 2 were given
这意味着在您的 django 应用程序中,“应用程序”在通过 WSGI 发出第一个请求之前没有以正确的方式设置。
WSGI 标准需要一个 object 的“应用程序”,它可以通过参数调用,以便将 http 请求路由到 Django 应用程序:
application(environ, start_response)
这是由 wsgi.py 中的代码提供的:
application = get_wsgi_application()
它在“应用程序”中实例化并存储一个 WSGIHandler Object。 如果之后您调用“应用程序”,则与调用相同
instance_of_WSGIHandler.__call__(... )
如果您查看 django 源代码,您会发现 WSGIHandler 类
# file django.core.handlers.wsgi:
class WSGIHandler(base.BaseHandler):
request_class = WSGIRequest
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.load_middleware()
def __call__(self, environ, start_response):
# handle the http request from wsgi interface
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.