Apache2 Django NameError:名称“TypeError”未定义

vik*_*kAy 5 django apache2 vps

我试图通过 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
Run Code Online (Sandbox Code Playgroud)

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

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

除此之外,我还补充了:

<Directory /var/www/mysite/mysite>
        <Files wsgi.py>
            Require all granted
        </Files>
</Directory>
Run Code Online (Sandbox Code Playgroud)

但再一次,没有改变

vik*_*kAy 3

因为这篇文章已被投票,也许它可以帮助其他人搜索该问题:这是我的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}/$1 [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>

Run Code Online (Sandbox Code Playgroud)