我有一个Django应用程序处理两个(或更多)网站的部分,例如该网站的“管理”和“api”部分。我还为网站的其他部分提供了普通的html页面,其中不需要Django。Apache配置为静态网站的根和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,使用这样的网址:
# my_app/urls.py
...
url(r'^admin/', include('admin.urls')),
url(r'^api/', include('api.urls')),
url(r'^(?P<path>.*)$', ??????????),
...
但我找不出一个很好的方式将这些静态页面的服务委托给Apache。 (它的工作,如果我使用url(r'^(?P<path>.*)$, 'django.views.static.serve', {'document_root': '/path/to/static/site'})
,但Django文档禁止使用该生产服务器上)
然后我试图与Apache的配置:
# httpd.conf
...
DocumentRoot /path/to/static/site
WSGIScriptAlias /admin /path/to/django/my_app/wsgi.py
WSGIScriptAlias /api /path/to/django/my_app/wsgi.py
...
这个工作就请求根返回静态网站和请求都“管理”和“api”将返回Django网站,但在Django中,我发现无法区分请求来自'/ admin'还是'/ api'。 (加上我不知道,如果有在同一WSGI 2 WSGIScriptAlias
指点可能会引起一些问题。)
如果有人知道的方式来实现这一目标,而不必到我的Django应用程序分成两个(或更多)部分将不胜感激。