Apache2 Django NameError: name "TypeError" is not defined

Apache2 Django NameError: name "TypeError" is not defined

我正在尝试通过 apache2 运行 VPS 上的 django 应用程序,但我在网站错误文件中得到以下信息,也是 400(错误请求):

Exception ignored in: <function Local.__del__ at 0x7f47273f48b0>
Traceback (most recent call last):
  File "/usr/local/lib/python3.8/dist-packages/asgiref/local.py", line 96, in __del__
NameError: name 'TypeError' is not defined

我成功地 运行 一个使用“django-admin startproject”制作并可以查看的简单网站,但是上传使用以下框架制作的项目会产生此错误:https://django-project-skeleton.readthedocs.io/en/latest/apache2_vhost.html

我已经尝试在 WSGIDaemon 中包含 python 站点包,并通过排除它们产生相同的效果。

除此之外,我还补充了:

<Directory /var/www/mysite/mysite>
        <Files wsgi.py>
            Require all granted
        </Files>
</Directory>

但同样,没有变化

因为这个 post 被投票了,也许它可以帮助其他人搜索那个问题:这是我的 website.conf,只需将示例更改为您的域名。它还会重定向到您网站的 https 版本:

<VirtualHost *:80>    
    ServerName example.com
    ServerAlias www.example.com
    DocumentRoot /var/www/example
    
    RewriteEngine On
    RewriteCond %{HTTPS} !=on
    RewriteRule ^/?(.*) https://%{SERVER_NAME}/ [R,L]
    
</VirtualHost>

<VirtualHost *:443>    
    ServerName example.com
    ServerAlias www.example.com
    DocumentRoot /var/www/example
    # Insert the full path to the wsgi.py-file here
    WSGIScriptAlias /   /var/www/example/example/wsgi.py
   
    Alias /static/ /var/www/example/run/static/
    Alias /media/ /var/www/example/run/media/
 
    WSGIDaemonProcess   example python-path=/var/www/example

    # PROCESS_GROUP specifies a distinct name for the process group
    WSGIProcessGroup    example
    
    <Directory /var/www/example/example>
    <Files wsgi.py>
        Require all granted
    </Files>
    </Directory>
  
    <Directory /var/www/example/run/static>
        Require all granted
    </Directory>

    <Directory /var/www/example/run/media>
        Require all granted
    </Directory>

    LogLevel info

    ErrorLog    ${APACHE_LOG_DIR}/example_error.log
    CustomLog   ${APACHE_LOG_DIR}/example_access.log combined

    SSLEngine on
    SSLCertificateFile /var/ssl/example.crt
    SSLCertificateKeyFile /var/ssl/example.key
    SSLCertificateChainFile /var/ssl/example.ca-bundle

</VirtualHost>

打开您的 Apache 配置文件,然后在标签内添加“LogLevel 信息”:VirtualHost 最后(在关闭标签之前)。对我有用