Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/350.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/svg/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 根目录上静态站点的Apache配置和子位置上的Django_Python_Django_Apache - Fatal编程技术网

Python 根目录上静态站点的Apache配置和子位置上的Django

Python 根目录上静态站点的Apache配置和子位置上的Django,python,django,apache,Python,Django,Apache,我有一个Django应用程序,可以处理站点的两个(或更多)部分,例如站点的“admin”和“api”部分。我还为网站的其余部分提供了正常的html页面,在那里不需要Django 例如,我希望在我的站点根目录上有静态html站点,在一些子位置上有Django应用程序 www.example.com -> Apache static html site www.example.com/admin/ -> Django app, serving the pages for t

我有一个Django应用程序,可以处理站点的两个(或更多)部分,例如站点的“admin”和“api”部分。我还为网站的其余部分提供了正常的html页面,在那里不需要Django

例如,我希望在我的站点根目录上有静态html站点,在一些子位置上有Django应用程序

www.example.com        -> Apache static html site
www.example.com/admin/ -> Django app, serving the pages for the admin
www.example.com/api/   -> Django app, serving the pages for the api

首先,我尝试以Django的形式使用如下URL:

# my_app/urls.py
...
url(r'^admin/', include('admin.urls')),
url(r'^api/', include('api.urls')),
url(r'^(?P<path>.*)$', ??????????),
...
对于root用户的请求返回静态站点,而对“admin”和“api”的请求都将返回Django站点,这一点是有效的,但在Django中,我无法区分请求是来自“/admin”还是来自“/api”。(另外,我不确定两个
WSGIScriptAlias
指向同一个wsgi是否会导致一些问题。)



如果有人知道一种不必将我的Django应用程序分成两个(或更多)部分就可以实现这一点的方法,那将不胜感激。

我遇到了几乎完全相同的问题。在Apaches虚拟主机配置中供站点使用

WSGIScriptAliasMatch ^(/(admin|api)) /path/to/django/my_app/wsgi.py$1
而不是

WSGIScriptAlias /admin /path/to/django/my_app/wsgi.py
WSGIScriptAlias /api   /path/to/django/my_app/wsgi.py
查看这些问答了解更多信息:

WSGIScriptAlias /admin /path/to/django/my_app/wsgi.py
WSGIScriptAlias /api   /path/to/django/my_app/wsgi.py