【发布时间】:2021-06-30 00:03:16
【问题描述】:
这里假设
testsite.com 这是我的 php 应用程序和
testsite.com/project 是 python-django 应用程序
我的 apache 站点配置文件 /etc/apache2/sites-available/site.conf 中有以下设置
<VirtualHost *:443>
ServerAdmin webmaster@testsite.com
ServerName testsite.com
DocumentRoot /var/www/html
WSGIDaemonProcess test python-path=/var/www/html/projectenv/test-project python-home=/var/www/html/projectenv
WSGIProcessGroup test
WSGIScriptAlias /project /var/www/html/projectenv/test-project/test-project/wsgi.py
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
注意:我必须将 WSGIScriptAlias 保留为 /project,因为只有这个 url 我的 django 项目才能工作。
但是当我点击testsite.com/project 时,它会出现以下错误
Page not found (404)
Using the URLconf defined in test-project.urls, Django tried these URL patterns, in this order:
admin/
project/
The empty path didn't match any of these.
这是我的项目 url 结构
urlpatterns = [
path('admin/', admin.site.urls),
path('', include('projectapp.urls'))
]
projectapp/urls.py
from django.urls import path
from . import views
urlpatterns = [
path('project/', views.home, name='project'),
]
settings.py
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'django_filters',
'projectapp',
]
请提出解决方案,当我点击这个 url testsite.com/project 它应该通过我定义的 django 应用程序并呈现链接到这个视图的页面,它观察到 wsgi 无法通过 django 项目结构并且由于它没有识别应用程序中给出的 url。或者可能是它无法找到应用程序结构。
为了使这项工作我应该改变什么,请提出建议
【问题讨论】:
-
如果您使用
testsite.com/project,它将在testsite.com目录中查找project,因为它是一个不同的项目,所以它不会存在。您最好使用project作为子域。 IE。project.testsite.com -
@Anthony:testsite.com 不是目录。是我的网站域,所以每当这个 url 命中它通过 virtualhost 中提到的文档根目录时,我建议请在
site.conf文件中仔细检查我的项目结构我想使用 url/project来呈现我的django 应用程序。所以请相应地提出建议
标签: python django apache apache2