2

我希望有多个 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

#取消注释接下来的两行以启用管理员: from django.contrib import admin admin.autodiscover()

urlpatterns = patterns('', # 示例:# 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)), )

我不知道问题是什么。

4

1 回答 1

2

你不应该使用:

WSGIScriptAliasMatch ^/adam(.*) /home/ajt1g09/bms/apache/django.wsgi

只需使用:

WSGIScriptAlias /adam /home/ajt1g09/bms/apache/django.wsgi

WSGIScriptAliasMatch 不会像所写的那样工作,因为您没有将匹配的部分重新替换为最后一个参数。IE。,

WSGIScriptAliasMatch ^/adam(.*) /home/ajt1g09/bms/apache/django.wsgi$1

尽管您应该根本不使用 WSGIScriptAliasMatch。这仅适用于高级用例,并且需要您在使用它时非常小心,因为您使用它的方式会影响传递给应用程序时设置的 SCRIPT_NAME/PATH_INFO 的设置,并且是 urls.py 匹配所基于的那些。

于 2011-06-29T23:51:05.473 回答