2

複数のdjangoをインストールしたい。1 つは / (正常に動作しています) に、もう 1 つは /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

#次の 2 行のコメントを外して、admin を有効にします: 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 は、一致した部分を最後の引数に再置換していないため、記述どおりには機能しません。すなわち、

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

ただし、WSGIScriptAliasMatch を使用するべきではありません。これは高度なユースケースのみを対象としており、使用方法はアプリケーションに渡されるときに SCRIPT_NAME/PATH_INFO の設定に影響を与える可能性があり、urls.py マッチングのベースとなるため、使用には細心の注意が必要です。

于 2011-06-29T23:51:05.473 に答える