Skip to main content
 首页 » 编程设计

python之类型错误 : __init__() got an unexpected keyword argument 'current_app'

2025年02月15日26zengkefu

我在运行 CentOS 7 的服务器上使用 Django 1.11 (Python/2.7.5) + Apache/2.4.6 + mod_wsgi/3.4 部署了一个应用程序。

页面工作正常,但登录后出现以下错误:

TypeError at / 
__init__() got an unexpected keyword argument 'current_app' 
 
Request Method: GET 
Request URL:    http://server.url/ 
Django Version: 1.11.1 
Exception Type: TypeError 
Exception Value: __init__() got an unexpected keyword argument 'current_app' 
Exception Location: /usr/lib/python2.7/site-packages/django/shortcuts/__init__.py in render, line 49 
Python Executable:  /usr/bin/python 
Python Version: 2.7.5 
Python Path:     
    ['/var/www/html/webINR', 
    '/usr/lib64/python27.zip', 
    '/usr/lib64/python2.7', 
    '/usr/lib64/python2.7/plat-linux2', 
    '/usr/lib64/python2.7/lib-tk', 
    '/usr/lib64/python2.7/lib-old', 
    '/usr/lib64/python2.7/lib-dynload', 
    '/usr/lib64/python2.7/site-packages', 
    '/usr/lib/python2.7/site-packages'] 
    Server time:    Wed, 17 May 2017 12:31:10 +0000  

异常在 render 行:

@login_required 
    def index(request): 
    return render(request, 'base.html') 

我认为错误不是由 Apache 和/或 mod_wsgi 引起的(因为该页面在线)。有帮助吗?

请您参考如下方法:

这似乎是一个常见问题。

这很可能与版本不匹配或服务器上的旧 Django 文件夹有关。

  1. 确保卸载 Django
  2. 检查以确保没有旧版本 Django 的任何文件夹。
  3. 重新安装 Django

编辑:可能还应该提到重启服务器。