python - django 1.10 中的自定义设置和 wsgi 给我错误

标签 python django wsgi

我在运行服务器的自定义设置中遇到了这个错误:

 salahaddin@TulipanROG  ~/Proyectos/tiempoturco/tiempoturco  (tiempoturco)  ./manage.py runserver                                                                                                                                            ✓  640  23:22:06 
Performing system checks...

System check identified no issues (0 silenced).
June 19, 2016 - 23:22:07
Django version 1.10a1, using settings 'tiempoturco.settings.dev'
Starting development server at http://127.0.0.1:8000/
Quit the server with CONTROL-C.
Unhandled exception in thread started by <function check_errors.<locals>.wrapper at 0x7f288d67f2f0>
Traceback (most recent call last):
  File "/home/salahaddin/Proyectos/tiempoturco/lib/python3.5/site-packages/django/utils/autoreload.py", line 226, in wrapper
    fn(*args, **kwargs)
  File "/home/salahaddin/Proyectos/tiempoturco/lib/python3.5/site-packages/django/core/management/commands/runserver.py", line 142, in inner_run
    handler = self.get_handler(*args, **options)
  File "/home/salahaddin/Proyectos/tiempoturco/lib/python3.5/site-packages/django/contrib/staticfiles/management/commands/runserver.py", line 27, in get_handler
    handler = super(Command, self).get_handler(*args, **options)
  File "/home/salahaddin/Proyectos/tiempoturco/lib/python3.5/site-packages/django/core/management/commands/runserver.py", line 64, in get_handler
    return get_internal_wsgi_application()
  File "/home/salahaddin/Proyectos/tiempoturco/lib/python3.5/site-packages/django/core/servers/basehttp.py", line 49, in get_internal_wsgi_application
    return import_string(app_path)
  File "/home/salahaddin/Proyectos/tiempoturco/lib/python3.5/site-packages/django/utils/module_loading.py", line 20, in import_string
    module = import_module(module_path)
  File "/home/salahaddin/Proyectos/tiempoturco/lib/python3.5/importlib/__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 986, in _gcd_import
  File "<frozen importlib._bootstrap>", line 969, in _find_and_load
  File "<frozen importlib._bootstrap>", line 958, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 673, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 662, in exec_module
  File "<frozen importlib._bootstrap>", line 222, in _call_with_frames_removed
  File "/home/salahaddin/Proyectos/tiempoturco/tiempoturco/tiempoturco/wsgi.py", line 16, in <module>
    application = get_wsgi_application()
  File "/home/salahaddin/Proyectos/tiempoturco/lib/python3.5/site-packages/django/core/wsgi.py", line 14, in get_wsgi_application
    return WSGIHandler()
  File "/home/salahaddin/Proyectos/tiempoturco/lib/python3.5/site-packages/django/core/handlers/wsgi.py", line 153, in __init__
    self.load_middleware()
  File "/home/salahaddin/Proyectos/tiempoturco/lib/python3.5/site-packages/django/core/handlers/base.py", line 79, in load_middleware
    mw_instance = middleware(handler)
TypeError: object() takes no parameters

我有这个文件夹结构: enter image description here

这是我的 wsgi 代码:

import os

from django.core.wsgi import get_wsgi_application

os.environ.setdefault("DJANGO_SETTINGS_MODULE", "tiempoturco.settings.dev")

application = get_wsgi_application()

还有我的 manage.py 代码:

#!/usr/bin/env python
import os
import sys

if __name__ == "__main__":
    os.environ.setdefault("DJANGO_SETTINGS_MODULE", "tiempoturco.settings.dev")
    try:
        from django.core.management import execute_from_command_line
    except ImportError:
        # The above import may fail for some other reason. Ensure that the
        # issue is really that Django is missing to avoid masking other
        # exceptions on Python 2.
        try:
            import django
        except ImportError:
            raise ImportError(
                "Couldn't import Django. Are you sure it's installed and "
                "available on your PYTHONPATH environment variable? Did you "
                "forget to activate a virtual environment?"
            )
        raise
    execute_from_command_line(sys.argv)

怎么了? 我可以执行迁移并创建 super 用户,使用 shell plus 和其他命令,但我可以运行服务器。我尝试将设置值更改为 production 和 dev,将这些值放入 __init__.py 并执行其他操作,但什么也没做。

middleware_classes:

MIDDLEWARE_CLASSES = [
    'django.middleware.security.SecurityMiddleware',
    'django.contrib.sessions.middleware.SessionMiddleware',
    'django.middleware.common.CommonMiddleware',
    'django.middleware.csrf.CsrfViewMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
    'django.contrib.messages.middleware.MessageMiddleware',
    'django.middleware.clickjacking.XFrameOptionsMiddleware',
]

我找不到相关信息,我正在测试 django 1.10

我对 django 1.9.7 没有问题,我不知道为什么。同样,当我使用 wagtail 1.6 创建项目时,我在运行服务器中没有问题,wagtail 1.6 安装 django 1.9.7,但我将其替换为 django 1.10 然后尝试在运行迁移后运行该项目并创建一个 super 用户,当我在浏览器中进入主页时我可以看到页面和管理员.

所以,我没有使用其他应用程序的问题,但我自己手动创建多个设置给了我这个错误。

谁能帮帮我?

最佳答案

将我的应用程序升级到 Django 1.10 时,我遇到了类似的问题。首先,我会尝试将 MIDDLEWARE_CLASSES 更改为 MIDDLEWARE,因为在 Django 1.10 中,他们在这里引入了一种新的中间件样式:

https://docs.djangoproject.com/en/1.10/releases/1.10/

如果这不起作用,我建议检查你的 django 中间件文件,我必须将所有接受对象的类更改为 MiddlewareMixin,你可以通过调用导入它:

from django.utils.deprecation import MiddlewareMixin

在我的例子中我改变了

class SiteMiddleware(object):
...

from django.utils.deprecation import MiddlewareMixin

class SiteMiddleware(MiddlewareMixin):
...

关于python - django 1.10 中的自定义设置和 wsgi 给我错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37914645/

相关文章:

python - ttk TreeView : How to select a row?

python - tensorflow TFRecord : Can't parse serialized example

python - 连接到本地主机数据库的 python 中的搜索框

django - HTML 输入当前不支持列表

python - 从 virtualenv 中启动 wsgi 应用程序作为 Linux 系统服务

Python mod_wsgi 不工作

python - 如何使用 WSGIREF 捕获 POST

python - 使用 python 在循环中的 csv 中添加新列

python - Django 导入 LDAP 库

python - 正在生成多少个查询?