当前 URL 与其中任何一个都不匹配 - 使用多个站点
我希望安装多个 django。一个位于 / (工作正常),另一个位于 /adam。斜线 adam 处的地址会被 apache 正确重定向,直到您尝试访问某个应用程序为止。例如 /admin 有效,但 /adam/admin 无效。我收到错误:
Page not found (404)
Request Method: GET
Request URL: http://[CENSORED]/adam/
Using the URLconf defined in bms.urls, Django tried these URL patterns, in this order:
^admin/doc/
^admin/
The current URL, , didn't match any of these.
注意空逗号。 apache 虚拟主机是:
<VirtualHost *:80>
ServerName [CENSORED]
DocumentRoot /home/user/bms
Alias /static/admin/ /usr/local/lib/python2.7/site-packages/Django-1.3-py2.7.egg/django/contrib/admin/media/
<Directory /home/user/bms/apache>
Order allow,deny
Allow from all
</Directory>
<Directory /home/ajt1g09/bms/apache>
Order allow,deny
Allow from all
</Directory>
WSGIDaemonProcess bms user=user group=user processes=2 threads=25 python-path=/usr/local/lib/python2.7/site-packages
WSGIProcessGroup bms
WSGIScriptAliasMatch ^/adam(.*) /home/ajt1g09/bms/apache/django.wsgi
WSGIScriptAlias / /home/user/bms/apache/django.wsgi
</VirtualHost>
ajt1g09/bms/apache 中的 django.wsgi 文件:
import os
import sys
path = '/home/ajt1g09/bms'
if path not in sys.path:
sys.path.append(path)
sys.path.append('/usr/local/lib/python2.7/site-packages')
sys.path.append('/home/ajt1g09')
os.environ['DJANGO_SETTINGS_MODULE'] = 'bms.settings'
import django.core.handlers.wsgi
application = django.core.handlers.wsgi.WSGIHandler()
最后是 ajt1g09/bms 中的 urls.py 文件(清楚地显示 /admin 在那里):
从 django.conf.urls.defaults 导入 模式、包含、url
#取消注释接下来的两行以启用管理:来自 django.contrib 导入管理员 admin.autodiscover()
urlpatterns = 模式('', # 示例: # url(r'^$', 'bms.views.home', name='home'), # url(r'^bms/', include('bms.foo.urls')),
# 取消注释下面的 admin/doc 行以启用管理文档: url(r'^admin/doc/', include('django.contrib.admindocs.urls')), # 取消注释下一行以启用管理员: url(r'^admin/', include(admin.site.urls)), )
我不知道问题是什么。
I wish to have multiple django installations. One at / (which is working fine) and one at /adam. The one at slash adam is redirected by apache correctly, until you try and visit an app. E.g. /admin works but /adam/admin does not work. I get the error:
Page not found (404)
Request Method: GET
Request URL: http://[CENSORED]/adam/
Using the URLconf defined in bms.urls, Django tried these URL patterns, in this order:
^admin/doc/
^admin/
The current URL, , didn't match any of these.
Notice the empty commas. The apache virtual host is:
<VirtualHost *:80>
ServerName [CENSORED]
DocumentRoot /home/user/bms
Alias /static/admin/ /usr/local/lib/python2.7/site-packages/Django-1.3-py2.7.egg/django/contrib/admin/media/
<Directory /home/user/bms/apache>
Order allow,deny
Allow from all
</Directory>
<Directory /home/ajt1g09/bms/apache>
Order allow,deny
Allow from all
</Directory>
WSGIDaemonProcess bms user=user group=user processes=2 threads=25 python-path=/usr/local/lib/python2.7/site-packages
WSGIProcessGroup bms
WSGIScriptAliasMatch ^/adam(.*) /home/ajt1g09/bms/apache/django.wsgi
WSGIScriptAlias / /home/user/bms/apache/django.wsgi
</VirtualHost>
And the django.wsgi file in ajt1g09/bms/apache:
import os
import sys
path = '/home/ajt1g09/bms'
if path not in sys.path:
sys.path.append(path)
sys.path.append('/usr/local/lib/python2.7/site-packages')
sys.path.append('/home/ajt1g09')
os.environ['DJANGO_SETTINGS_MODULE'] = 'bms.settings'
import django.core.handlers.wsgi
application = django.core.handlers.wsgi.WSGIHandler()
And finally, the urls.py file in ajt1g09/bms (clearly showing /admin is there):
from django.conf.urls.defaults import
patterns, include, url#Uncomment the next two lines to enable the admin: from django.contrib
import admin
admin.autodiscover()urlpatterns = patterns('',
# Examples:
# url(r'^$', 'bms.views.home', name='home'),
# url(r'^bms/', include('bms.foo.urls')),# Uncomment the admin/doc line below to enable admin documentation: url(r'^admin/doc/', include('django.contrib.admindocs.urls')), # Uncomment the next line to enable the admin: url(r'^admin/', include(admin.site.urls)), )
I have no idea what the problem is.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您不应该使用:
只需使用:
WSGIScriptAliasMatch 将无法按编写的方式工作,因为您尚未将匹配的部分重新替换为最后一个参数。也就是说,
您不应该使用 WSGIScriptAliasMatch。这仅适用于高级用例,并且要求您在使用它时非常小心,因为您如何使用它可能会影响 SCRIPT_NAME/PATH_INFO 在传递给应用程序时设置的内容,而 urls.py 匹配正是基于这些内容。
You shouldn't be using:
Just use:
The WSGIScriptAliasMatch will not work as written because you haven't re substituted the matched part from back into last argument. Ie.,
You should though simply not be using WSGIScriptAliasMatch. That is for advanced use cases only and requires you be very careful in using it because how you use it can impact what SCRIPT_NAME/PATH_INFO are set to when passed to application and it is those that urls.py matching is based off.