我在弄清楚我的安装出了什么问题时遇到了很多麻烦。这是我第一次在生产服务器上设置 django 应用程序,所以我想我只需要一点帮助来弄清楚如何配置设置模块的路径。这就是我的 httpd.conf 文件中的内容。
<VirtualHost *:80>
ServerAdmin admin@example.com
ServerName nodeline.com
WSGIScriptAlias / /home/mysite/mysite/wsgi.py
</VirtualHost>
我使用这个命令在 /home 目录中启动了一个名为 mysite 的基本项目。
django-admin.py startproject mysite
这是 apache 错误日志中出现的内容:
[Sat Jul 06 02:49:42 2013] [error] [client 119.63.193.132] mod_wsgi (pid=26120): Exception occurred processing WSGI script '/home/mysite/mysite/wsgi.py'.
[Sat Jul 06 02:49:42 2013] [error] [client 119.63.193.132] Traceback (most recent call last):
[Sat Jul 06 02:49:42 2013] [error] [client 119.63.193.132] File "/usr/lib/python2.6/site-packages/django/core/handlers/wsgi.py", line 236, in __call__
[Sat Jul 06 02:49:42 2013] [error] [client 119.63.193.132] self.load_middleware()
[Sat Jul 06 02:49:42 2013] [error] [client 119.63.193.132] File "/usr/lib/python2.6/site-packages/django/core/handlers/base.py", line 45, in load_middleware
[Sat Jul 06 02:49:42 2013] [error] [client 119.63.193.132] for middleware_path in settings.MIDDLEWARE_CLASSES:
[Sat Jul 06 02:49:42 2013] [error] [client 119.63.193.132] File "/usr/lib/python2.6/site-packages/django/conf/__init__.py", line 53, in __getattr__
[Sat Jul 06 02:49:42 2013] [error] [client 119.63.193.132] self._setup(name)
[Sat Jul 06 02:49:42 2013] [error] [client 119.63.193.132] File "/usr/lib/python2.6/site-packages/django/conf/__init__.py", line 48, in _setup
[Sat Jul 06 02:49:42 2013] [error] [client 119.63.193.132] self._wrapped = Settings(settings_module)
[Sat Jul 06 02:49:42 2013] [error] [client 119.63.193.132] File "/usr/lib/python2.6/site-packages/django/conf/__init__.py", line 134, in __init__
[Sat Jul 06 02:49:42 2013] [error] [client 119.63.193.132] raise ImportError("Could not import settings '%s' (Is it on sys.path?): %s" % (self.SETTINGS_MODULE, e))
[Sat Jul 06 02:49:42 2013] [error] [client 119.63.193.132] ImportError: Could not import settings 'mysite.settings' (Is it on sys.path?): No module named mysite.settings
这是 /home/mysite/mysite/wsgi.py 文件中的内容(这是启动项目时文件附带的默认配置。):
"""
WSGI config for mysite project.
This module contains the WSGI application used by Django's development server
and any production WSGI deployments. It should expose a module-level variable
named ``application``. Django's ``runserver`` and ``runfcgi`` commands discover
this application via the ``WSGI_APPLICATION`` setting.
Usually you will have the standard Django WSGI application here, but it also
might make sense to replace the whole Django WSGI application with a custom one
that later delegates to the Django one. For example, you could introduce WSGI
middleware here, or combine a Django application with an application of another
framework.
"""
import os
# We defer to a DJANGO_SETTINGS_MODULE already in the environment. This breaks
# if running multiple sites in the same mod_wsgi process. To fix this, use
# mod_wsgi daemon mode with each site in its own daemon process, or use
# os.environ["DJANGO_SETTINGS_MODULE"] = "mysite.settings"
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "mysite.settings")
# This application object is used by any WSGI server configured to use this
# file. This includes Django's development server, if the WSGI_APPLICATION
# setting points here.
from django.core.wsgi import get_wsgi_application
application = get_wsgi_application()
# Apply WSGI middleware here.
# from helloworld.wsgi import HelloWorldApplication
# application = HelloWorldApplication(application)
我真的只需要显示标准屏幕,我知道我可以从那里继续前进。我还应该注意,当我仅使用 django 内置的开发服务器启动应用程序时,它就可以工作。我使用以下命令在端口 8000 上启动它:
python manage.py runserver 0:8000
访问 nodeline.com:8000 时,它可以工作。