“省略号”对象没有属性“lower”-当我运行python3manage.pyrunserver时

k10s72fa  于 2023-02-28  发布在  Python
关注(0)|答案(1)|浏览(121)

我正在linux ubuntu上运行一个web应用程序(wagtail cms),当我运行python3时,我收到了这个错误消息manage.pyrunserver 0.0.0.0:8000请查看控制台上的错误消息。

Performing system checks...

  System check identified no issues (0 silenced).
  March 22, 2018 - 15:27:33
  Django version 1.11.1, using settings 'ntdl.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 "/usr/local/lib/python3.6/dist-
  packages/django/core/handlers/exception.py", line 41, in inner
  response = get_response(request)
  File "/usr/local/lib/python3.6/dist-packages/django/utils/deprecation.py", 
  line 138, in __call__
  response = self.process_request(request)
  File "/usr/local/lib/python3.6/dist-
  packages/django/middleware/security.py", line 25, in process_request
  host = self.redirect_host or request.get_host()
  File "/usr/local/lib/python3.6/dist-packages/django/http/request.py", line 
   105, in get_host
  if domain and validate_host(domain, allowed_hosts):
  File "/usr/local/lib/python3.6/dist-packages/django/http/request.py", line 
   579, in validate_host
  if pattern == '*' or is_same_domain(host, pattern):
  File "/usr/local/lib/python3.6/dist-packages/django/utils/http.py", line 
  291, in is_same_domain
  pattern = pattern.lower()
  AttributeError: 'ellipsis' object has no attribute 'lower'
  "GET / HTTP/1.1" 500 11959
  Internal Server Error: /favicon.ico
  Traceback (most recent call last):
  File "/usr/local/lib/python3.6/dist-
  packages/django/core/handlers/exception.py", line 41, in inner
  response = get_response(request)
  File "/usr/local/lib/python3.6/dist-packages/django/utils/deprecation.py", 
  line 138, in __call__
  response = self.process_request(request)
  File "/usr/local/lib/python3.6/dist-
  packages/django/middleware/security.py", line 25, in process_request
  host = self.redirect_host or request.get_host()
  File "/usr/local/lib/python3.6/dist-packages/django/http/request.py", line 
  105, in get_host
  if domain and validate_host(domain, allowed_hosts):
  File "/usr/local/lib/python3.6/dist-packages/django/http/request.py", line 
  579, in validate_host
  if pattern == '*' or is_same_domain(host, pattern):
  File "/usr/local/lib/python3.6/dist-packages/django/utils/http.py", line 
  291, in is_same_domain
   pattern = pattern.lower()
   AttributeError: 'ellipsis' object has no attribute 'lower'
  "GET /favicon.ico HTTP/1.1" 500 11965

我已经进去了http.py检查了代码,它有下面的代码

def is_same_domain(host, pattern):
 """
 Return ``True`` if the host is either an exact match or a match
 to the wildcard pattern.

 Any pattern beginning with a period matches a domain and all of its
 subdomains. (e.g. ``.example.com`` matches ``example.com`` and
 ``foo.example.com``). Anything else is an exact string match.
 """
 if not pattern:
    return False

  pattern = pattern.lower()
  return (
     pattern[0] == '.' and (host.endswith(pattern) or host == pattern[1:]) 
   or
    pattern == host
  )

我在这里看不到任何错误。请帮助我修复此错误。
万分感谢,
巴拉特AK

5hcedyr0

5hcedyr01#

我没有太多的Django经验,但当我遇到这个问题时,使用下面的代码:

@api_view([...])
@permission_classes((permissions.AllowAny,))
def blog_list(request):
    return Response('successfull attempt')

但是只要删除@API_view装饰器中的[...],问题就解决了。

@api_view()
@permission_classes((permissions.AllowAny,))
def blog_list(request):
    return Response('successfull attempt')

相关问题