2017-04-09 120 views
-2

我更新了我的django從1.7到1.8,我的服務器不再運行了。'發生服務器錯誤。請聯繫管理員。'在Django 1.8.11

我做了什麼:

  • 試圖安裝Python 3.6:什麼也沒發生後,我運行安裝程序。
  • 卸載了Django 1.7並安裝了1.9。不幸的是,這個版本給我帶來了麻煩(服務器甚至沒有啓動)。
  • 卸載1.9並安裝1.8。現在它出現這個錯誤。

我在macOS Sierra上。 10.12.3。我的Python版本是2.7。

我需要爲了使用「從rest_framwork.view進口APIView」

有人可以幫助我的Django的1.8版本?

這裏的日誌:

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

[爲什麼*有人可以幫助我?]不是一個實際的問題?](https://meta.stackoverflow.com/q/284236/62576) –

回答

2

看起來你需要的ALLOWED_HOSTS settings

的Django 1.7和Django的1.8

From 1.7 Documentation之間的這種行爲改變:

當DEBUG爲如果爲真或運行測試,主機驗證將被禁用; 任何主機都將被接受。因此通常只需要將其設置爲 即可生產。

From 1.8 Documentation

當DEBUG爲True,並且ALLOWED_HOSTS是空的,主機驗證 針對[ '本地主機', '127.0.0.1', '[:1]']

您需要將此IP地址添加到這個設置

東西就行:

ALLOWED_HOSTS = ['192.168.0.101', 'localhost', '127.0.0.1', '[::1]'] 
+0

解決了我的問題!謝謝 –

相關問題