错误:在apache上运行django时找不到目标WSGI脚本或无法统计

roc*_*cky 6 apache django django-templates django-views

我在apache上运行django时遇到问题:

htdocs目录/博客/应用/主页/ urls.py:

url(r'^$', 'index', name="h_index"),
url(r'^about/$', 'about', name="h_about"),
url(r'^contact/$', 'contact', name="h_contact"),
url(r'^archive/$', 'archive', name="h_archive"),
Run Code Online (Sandbox Code Playgroud)

htdocs目录/博客/ urls.py

(r'^', include('apps.homepage.urls')),
Run Code Online (Sandbox Code Playgroud)

django.wsgi:

import os
import os.path
import sys

sys.path.append('D:/Coding/xampp/htdocs')
sys.path.append('D:/Coding/xampp/htdocs/blog')

os.environ['DJANGO_SETTINGS_MODULE'] = 'blog.settings'

import django.core.handlers.wsgi
application = django.core.handlers.wsgi.WSGIHandler()
Run Code Online (Sandbox Code Playgroud)

httpd.conf中:

Alias /static/ "D:/Coding/xampp/htdocs/blog/static/"
WSGIScriptAlias /blog/ "D:/Coding/xampp/htdocs/blog/django.wsgi"
Run Code Online (Sandbox Code Playgroud)

当我运行"localhost/blog"时,它正在运行.但运行"localhost/blog/about /"或其他,这是错误:

[error] [client ::1] Target WSGI script not found or unable to stat:   .../htdocs/blog/django.wsgiabout, referer: http://localhost/blog/
Run Code Online (Sandbox Code Playgroud)

小智 15

请注意您的apache配置与mod_wsgi的WSGIScriptAlias的文档语法不匹配.

WSGIScriptAlias /blog/ "D:/Coding/xampp/htdocs/blog/django.wsgi"

应该:

WSGIScriptAlias /blog "D:/Coding/xampp/htdocs/blog/django.wsgi"

(注意第二个标记后面没有斜杠,"/ blog")

我刚刚解决了同样的问题并发现了这个帖子谷歌搜索.希望这有助于您和未来的用户.

欲获得更多信息: