【发布时间】:2018-06-23 01:43:43
【问题描述】:
我在使用 bitnami django 时遇到了上述错误。 根据文档完成所有设置: https://docs.bitnami.com/virtual-machine/components/django/#production python版本:Python 3.6.4 :: Anaconda, Inc. django 版本:2.0.2-3
wsgi.py:
import os,sys
sys.path.append('/Applications/djangostack-2.0.2-3/apps/django/django_projects/MyProject')
os.environ.setdefault("PYTHON_EGG_CACHE", "/Applications/djangostack-2.0.2-3/apps/django/django_projects/MyProject/egg_cache")
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "MyProject.settings")
from django.core.wsgi import get_wsgi_application
application = get_wsgi_application()
httpd-app.conf:
<IfDefine !IS_DJANGOSTACK_LOADED>
Define IS_DJANGOSTACK_LOADED
WSGIDaemonProcess wsgi-djangostack processes=2 threads=15 display-name=%{GROUP}
</IfDefine>
<Directory "/Applications/djangostack-2.0.2-3/apps/django/django_projects/MyProject/MyProject">
Options +MultiViews
AllowOverride All
<IfVersion < 2.3 >
Order allow,deny
Allow from all
</IfVersion>
<IfVersion >= 2.3>
Require all granted
</IfVersion>
WSGIProcessGroup wsgi-djangostack
WSGIApplicationGroup %{GLOBAL}
Require all granted
</Directory>
Alias /MyProject/static "/Applications/djangostack-2.0.2-3/apps/django/lib/python3.6/site-packages/Django-2.0.2-py3.6.egg/django/contrib/admin/static"
WSGIScriptAlias /MyProject '/Applications/djangostack-2.0.2-3/apps/django/django_projects/MyProject/MyProject/wsgi.py'
httpd-prefix.conf:
# Include file
Include "/Applications/djangostack-2.0.2-3/apps/django/django_projects/MyProject/conf/httpd-app.conf"
对应的 url 添加到 /Applications/djangostack-2.0.2-3/apache2/conf/bitnami/bitnami-apps-prefix.conf 文件
但是当我尝试通过浏览器访问应用程序时,日志中出现错误:
[Fri Jun 22 16:37:20.873873 2018] [wsgi:error] [pid 29099] [remote ::1:62098] mod_wsgi (pid=29099): Target WSGI script '/Applications/djangostack-2.0.2-3/apps/django/django_projects/MyProject/MyProject/wsgi.py' cannot be loaded as Python module.
[Fri Jun 22 16:37:20.874027 2018] [wsgi:error] [pid 29099] [remote ::1:62098] mod_wsgi (pid=29099): Exception occurred processing WSGI script '/Applications/djangostack-2.0.2-3/apps/django/django_projects/MyProject/MyProject/wsgi.py'.
[Fri Jun 22 16:37:20.875482 2018] [wsgi:error] [pid 29099] [remote ::1:62098] Traceback (most recent call last):
[Fri Jun 22 16:37:20.875554 2018] [wsgi:error] [pid 29099] [remote ::1:62098] File "/Applications/djangostack-2.0.2-3/apps/django/django_projects/MyProject/MyProject/wsgi.py", line 17, in <module>
[Fri Jun 22 16:37:20.875568 2018] [wsgi:error] [pid 29099] [remote ::1:62098] application = get_wsgi_application()
[Fri Jun 22 16:37:20.875584 2018] [wsgi:error] [pid 29099] [remote ::1:62098] File "/Applications/djangostack-2.0.2-3/apps/django/lib/python3.6/site-packages/Django-2.0.2-py3.6.egg/django/core/wsgi.py", line 12, in get_wsgi_application
[Fri Jun 22 16:37:20.875594 2018] [wsgi:error] [pid 29099] [remote ::1:62098] django.setup(set_prefix=False)
[Fri Jun 22 16:37:20.875608 2018] [wsgi:error] [pid 29099] [remote ::1:62098] File "/Applications/djangostack-2.0.2-3/apps/django/lib/python3.6/site-packages/Django-2.0.2-py3.6.egg/django/__init__.py", line 24, in setup
[Fri Jun 22 16:37:20.875618 2018] [wsgi:error] [pid 29099] [remote ::1:62098] apps.populate(settings.INSTALLED_APPS)
[Fri Jun 22 16:37:20.875631 2018] [wsgi:error] [pid 29099] [remote ::1:62098] File "/Applications/djangostack-2.0.2-3/apps/django/lib/python3.6/site-packages/Django-2.0.2-py3.6.egg/django/apps/registry.py", line 89, in populate
[Fri Jun 22 16:37:20.875641 2018] [wsgi:error] [pid 29099] [remote ::1:62098] app_config = AppConfig.create(entry)
[Fri Jun 22 16:37:20.875654 2018] [wsgi:error] [pid 29099] [remote ::1:62098] File "/Applications/djangostack-2.0.2-3/apps/django/lib/python3.6/site-packages/Django-2.0.2-py3.6.egg/django/apps/config.py", line 90, in create
[Fri Jun 22 16:37:20.875664 2018] [wsgi:error] [pid 29099] [remote ::1:62098] module = import_module(entry)
[Fri Jun 22 16:37:20.875677 2018] [wsgi:error] [pid 29099] [remote ::1:62098] File "/Applications/djangostack-2.0.2-3/python/lib/python3.6/importlib/__init__.py", line 126, in import_module
[Fri Jun 22 16:37:20.875687 2018] [wsgi:error] [pid 29099] [remote ::1:62098] return _bootstrap._gcd_import(name[level:], package, level)
[Fri Jun 22 16:37:20.875700 2018] [wsgi:error] [pid 29099] [remote ::1:62098] File "<frozen importlib._bootstrap>", line 994, in _gcd_import
[Fri Jun 22 16:37:20.875728 2018] [wsgi:error] [pid 29099] [remote ::1:62098] File "<frozen importlib._bootstrap>", line 971, in _find_and_load
[Fri Jun 22 16:37:20.875736 2018] [wsgi:error] [pid 29099] [remote ::1:62098] File "<frozen importlib._bootstrap>", line 953, in _find_and_load_unlocked
[Fri Jun 22 16:37:20.875752 2018] [wsgi:error] [pid 29099] [remote ::1:62098] ModuleNotFoundError: No module named 'widget_tweaks'
我已经安装了 widget_tweaks 使用:
pip3 install django-widget-tweaks
但是当我停止 Apache 并使用命令运行应用程序时
python3 manage.py runserver localhost:8080
该应用运行良好。
我在 /Applications/djangostack-2.0.2-3/apps/django/django_projects/MyProject/MyProject 下的 urls.py 看起来像:
from django.contrib import admin
from django.urls import path, include,re_path
urlpatterns = [
path('', include('APP.urls')),
re_path(r'^admin/', admin.site.urls, name='admin'),
]
所以我假设 Apache 配置中存在错误。任何帮助或建议将不胜感激!
【问题讨论】:
-
您是如何安装为 Anaconda Python 编译的 mod_wsgi 版本的? mod_wsgi 的系统包不能与 Anaconda Python 一起使用,因为 mod_wsgi 需要使用您要使用的特定 Python 安装/版本进行编译。
-
当你看到这个错误信息时,你调用了哪个 url?
-
我可以看看你的 urls.py
-
嗨@Mohammad,我正在编辑问题以附上我的urls.py
-
我调用的 URL 是 localhost:8080/MyProject
标签: django python-3.x apache mod-wsgi bitnami