我将django从1.7更新到1.8,我的服务器已不再运行了。
我做了什么:
- 尝试安装python 3.6:运行安装程序后没有任何反应。
- 卸载了Django 1.7并安装了1.9。不幸的是,这个版本给我带来了麻烦(服务器甚至没有开始)。
- 卸载1.9并安装1.8。现在它收到了这个错误。
我在macOS Sierra上。 10.12.3。我的python版本是2.7。
我需要Django的1.8版才能使用'来自rest_framwork.view导入APIView'
有人可以帮助我吗?
这是日志:
System check identified no issues (0 silenced).
April 09, 2017 - 01:35:43
Django version 1.8.18, using settings 'connectedin.settings'
Starting development server at http://192.168.0.101:8000/
Quit the server with CONTROL-C.
Traceback (most recent call last):
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/wsgiref/handlers.py", line 85, in run
self.result = application(self.environ, self.start_response)
File "/Library/Python/2.7/site-packages/Django-1.8.18-py2.7.egg/django/contrib/staticfiles/handlers.py", line 63, in __call__
return self.application(environ, start_response)
File "/Library/Python/2.7/site-packages/Django-1.8.18-py2.7.egg/django/core/handlers/wsgi.py", line 189, in __call__
response = self.get_response(request)
File "/Library/Python/2.7/site-packages/Django-1.8.18-py2.7.egg/django/core/handlers/base.py", line 207, in get_response
return debug.technical_500_response(request, *sys.exc_info(), status_code=400)
File "/Library/Python/2.7/site-packages/Django-1.8.18-py2.7.egg/django/views/debug.py", line 97, in technical_500_response
html = reporter.get_traceback_html()
File "/Library/Python/2.7/site-packages/Django-1.8.18-py2.7.egg/django/views/debug.py", line 384, in get_traceback_html
return t.render(c)
File "/Library/Python/2.7/site-packages/Django-1.8.18-py2.7.egg/django/template/base.py", line 210, in render
return self._render(context)
File "/Library/Python/2.7/site-packages/Django-1.8.18-py2.7.egg/django/template/base.py", line 202, in _render
return self.nodelist.render(context)
File "/Library/Python/2.7/site-packages/Django-1.8.18-py2.7.egg/django/template/base.py", line 905, in render
bit = self.render_node(node, context)
File "/Library/Python/2.7/site-packages/Django-1.8.18-py2.7.egg/django/template/debug.py", line 79, in render_node
return node.render(context)
File "/Library/Python/2.7/site-packages/Django-1.8.18-py2.7.egg/django/template/defaulttags.py", line 329, in render
return nodelist.render(context)
File "/Library/Python/2.7/site-packages/Django-1.8.18-py2.7.egg/django/template/base.py", line 905, in render
bit = self.render_node(node, context)
File "/Library/Python/2.7/site-packages/Django-1.8.18-py2.7.egg/django/template/debug.py", line 79, in render_node
return node.render(context)
File "/Library/Python/2.7/site-packages/Django-1.8.18-py2.7.egg/django/template/debug.py", line 89, in render
output = self.filter_expression.resolve(context)
File "/Library/Python/2.7/site-packages/Django-1.8.18-py2.7.egg/django/template/base.py", line 648, in resolve
obj = self.var.resolve(context)
File "/Library/Python/2.7/site-packages/Django-1.8.18-py2.7.egg/django/template/base.py", line 789, in resolve
value = self._resolve_lookup(context)
File "/Library/Python/2.7/site-packages/Django-1.8.18-py2.7.egg/django/template/base.py", line 849, in _resolve_lookup
current = current()
File "/Library/Python/2.7/site-packages/Django-1.8.18-py2.7.egg/django/http/request.py", line 152, in build_absolute_uri
host=self.get_host(),
File "/Library/Python/2.7/site-packages/Django-1.8.18-py2.7.egg/django/http/request.py", line 102, in get_host
raise DisallowedHost(msg)
DisallowedHost: Invalid HTTP_HOST header: '192.168.0.101:8000'. You may need to add u'192.168.0.101' to ALLOWED_HOSTS.
[09/Apr/2017 01:35:51] "GET / HTTP/1.1" 500 59
答案 0 :(得分:2)
此行为在django 1.7]和django 1.8之间发生了变化
当DEBUG为True或运行测试时,主机验证被禁用; 任何主人都会被接受。因此,通常只需要设置它 在生产中。
当DEBUG为True且ALLOWED_HOSTS为空时,验证主机 反对['localhost','127.0.0.1','[:: 1]']
您需要将此IP地址添加到此设置
有些内容:
ALLOWED_HOSTS = ['192.168.0.101', 'localhost', '127.0.0.1', '[::1]']