如何在mod_wsgi的相同域(apache2)上运行Django和PHP?

我想在同一个域中运行Django和PHP(例如,当我访问192.168.14.10时,索引页面正确显示,PHP从索引页面调用)。当我运行下面的代码时,HTML代码中的数据只是完整的PHP和PHP的代码不起作用。

HTML(myproject / templates / test.html)

<body> <form id="form_test"> <button type="button" onclick="exec_php()">Send</button> <script> function exec_php() { var formdata = new FormData($('#form_test').get(0)); $.ajax({ url: "../testphp", type: "POST", data: formdata, cache: false, contentType: false, processData: false, dataType: "text" }) .done(function (data, textStatus, jqXHR) { alert("data: " + data); }) .fail(function (jqXHR, textStatus, errorThrown) { alert("fail"); }); } </script> </form> </body> 

PHP(myprojcet / templates / test.php)

 <?php echo "php test" #this is a php test. 

我将../testphp的url与urls.py中的myproject / templates / test.php关联起来。

我如下设置/etc/apache2/sites-enabled/django.conf。

 LoadModule wsgi_module /usr/lib/apache2/modules/mod_wsgi-py35.cpython-35m-arm-linux-gnueabihf.so WSGIScriptAlias / /home/myproject/test/wsgi.py <Directory /home/myproject> Require all granted </Directory> <Directory /home/myproject/templates> Require all granted </Directory> Alias /static/ /home/myproject/static/ <Directory /home/myproject/static> Require all granted </Directory> 

wsgi.py(/home/myprojcet/test/wsgi.py)

 "" WSGI config for htmltest project. It exposes the WSGI callable as a module-level variable named ``application``. For more information on this file, see https://docs.djangoproject.com/en/1.10/howto/deployment/wsgi/ """ import os import sys from django.core.wsgi import get_wsgi_application print(sys.version_info) sys.path.append('home/myproject') sys.path.append('home/myproject/app') os.environ.setdefault("DJANGO_SETTINGS_MODULE", "test.settings") application = get_wsgi_application() 

apache2的configuration如下。

/etc/apache2/apache2.conf中

 <Directory /> Options FollowSymLinks AllowOverride None Require all denied </Directory> <Directory /usr/share> AllowOverride None Require all granted </Directory> <Directory /var/www> Options Indexes FollowSymLinks AllowOverride None Require all granted </Directory> 

我在urls.py中设置的HTML页面显示正确,所以我想我可以正确设置mod_wsgi。 但是PHP不能使用mod_wsgi。 当我把php文件放在documentroot中时,PHP正常工作,我使用runserver。

我应该怎么做才能让PHP在Apache2上使用django?