如何在没有虚拟环境的情况下在Linux apache(生产)上部署python django

时间:2020-04-30 11:48:50

标签: django linux apache2 mod-wsgi wsgi

OS: Linux Debian (last build)
Python: 3.7.7 64bit
python: 3.8.2 64bit
Django: 3.0
Apache2: 2.4.x

我正在尝试在Linux apache2(生产环境)上运行和测试我的Django项目。

我想通过pymysql模块在​​数据库中插入一条记录(当用户输入的字符串正确/错误(日志)时)。

下面的函数(check_usr())在测试环境(127.0.0.1:8000)中可以正常工作。但不适用于生产环境。

我只是通过网络浏览器在validate()视图中看到else部分的内容。

def check_usr (usernameee):
    result = subprocess.run(['........'], stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=False)
    result = result.stdout.decode('utf-8')
    if "successfully" in result:
        return "ok"
    elif "activation failed" in result:
        return "no"
    else:
        return "problem"

@require_http_methods(["GET"])
def validation(request):
    usernameee = request.GET["usernameee"]
    result = check_usr(usernameee)
    db_connection("init")

    if result == "ok":
        args = (ap_ssid, ap_mac, "ok")
        db_connection("INSERT INTO splash_tble (ap_ssid, ap_bssid, ap_state) VALUES (%s, %s, %s)", args)  
        return render(request, "router/validation.html", {"validation_state": "success"})

    elif result == "no":
        args = (ap_ssid, ap_mac, "no")
        db_connection("INSERT INTO splash_tble (ap_ssid, ap_bssid, ap_state) VALUES (%s, %s, %s)", args)  
        return render(request, "router/validation.html", {"validation_state": "failed"})

    else:
        return render(request, "router/validation.html", {"validation_state": "problem"})

我在/etc/apache2/sites-available/routers.conf中的配置:

DocumentRoot /root/PycharmProjects/router
WSGIScriptAlias / /root/PycharmProjects/router/captives/wsgi.py
WSGIPythonPath /root/PycharmProjects/router

<Directory /root/PycharmProjects/router>
   <Files wsgi.py>
      Order deny,allow
      Allow from all
      Require all granted 
   </Files>
</Directory>
Alias /static/ /root/PycharmProjects/router/captive_splash/static/
<Directory /root/PycharmProjects/router/captive_splash/static> 
  Order deny,allow
  Allow from all
  Require all granted 
</Directory> 

请帮助我诊断和运行Django中的check_usr()函数。

0 个答案:

没有答案