- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
所以我有一个 AngularJS/Django/Apache 项目,是在一位前员工离开后我才开始做的。到目前为止,这非常简单,但我正试图让 Django/Apache 能够很好地协同工作,但它不起作用。
既然这是一个“模块未找到错误”,是否有可能由于某种原因在路径上找不到 my_report 目录,或者存在权限错误?
我通常是一名 Java/MySql 开发人员,并且习惯使用 Python 作为后端脚本语言,因此这对我来说有点新鲜:P
整个项目位于/var/www/html/CoreRubrics/DjangoBackend 目录中,结构如下。
drwxr-xr-x. 2 apache users 5 Apr 21 16:01 CourseLists
-rw-r--r--. 1 apache users 250 Apr 21 16:01 manage.py
drwxr-xr-x. 2 apache users 4 Apr 21 16:01 scripts
drwxr-xr-x. 3 apache users 14 Apr 21 16:30 my_report
drwxr-xr-x. 2 apache users 3 Apr 21 17:04 apache
drwxr-xr-x. 2 apache users 8 Apr 23 11:19 my_proj
我有 apache 为前端 AngularJS 提供完美的服务,但是 Apache 在日志中给出了以下错误。
[Thu Apr 23 11:15:23.230040 2015] [:info] [pid 15039] [client 172.16.75.13:57216] mod_wsgi (pid=15039, process='', application='<<url goes here>>|/corerubric/cr'): Loading WSGI script '/var/www/html/CoreRubrics/DjangoBackend/apache/django.wsgi'., referer: <<url goes here>>/
[Thu Apr 23 11:15:23.803198 2015] [:error] [pid 15039] [client 172.16.75.13:57216] mod_wsgi (pid=15039): Target WSGI script '/var/www/html/CoreRubrics/DjangoBackend/apache/django.wsgi' cannot be loaded as Python module., referer: <<url goes here>>/
[Thu Apr 23 11:15:23.803253 2015] [:error] [pid 15039] [client 172.16.75.13:57216] mod_wsgi (pid=15039): Exception occurred processing WSGI script '/var/www/html/CoreRubrics/DjangoBackend/apache/django.wsgi'., referer: <<url goes here>>/
[Thu Apr 23 11:15:23.803304 2015] [:error] [pid 15039] [client 172.16.75.13:57216] Traceback (most recent call last):, referer: <<url goes here>>/
[Thu Apr 23 11:15:23.803346 2015] [:error] [pid 15039] [client 172.16.75.13:57216] File "/var/www/html/CoreRubrics/DjangoBackend/apache/django.wsgi", line 12, in <module>, referer: <<url goes here>>/
[Thu Apr 23 11:15:23.803670 2015] [:error] [pid 15039] [client 172.16.75.13:57216] application = get_wsgi_application(), referer: <<url goes here>>/
[Thu Apr 23 11:15:23.803704 2015] [:error] [pid 15039] [client 172.16.75.13:57216] File "/usr/lib/python2.7/site-packages/django/core/wsgi.py", line 14, in get_wsgi_application, referer: <<url goes here>>/
[Thu Apr 23 11:15:23.803784 2015] [:error] [pid 15039] [client 172.16.75.13:57216] django.setup(), referer: <<url goes here>>/
[Thu Apr 23 11:15:23.803816 2015] [:error] [pid 15039] [client 172.16.75.13:57216] File "/usr/lib/python2.7/site-packages/django/__init__.py", line 21, in setup, referer: <<url goes here>>/
[Thu Apr 23 11:15:23.804003 2015] [:error] [pid 15039] [client 172.16.75.13:57216] apps.populate(settings.INSTALLED_APPS), referer: <<url goes here>>/
[Thu Apr 23 11:15:23.804044 2015] [:error] [pid 15039] [client 172.16.75.13:57216] File "/usr/lib/python2.7/site-packages/django/apps/registry.py", line 85, in populate, referer: <<url goes here>>/
[Thu Apr 23 11:15:23.804376 2015] [:error] [pid 15039] [client 172.16.75.13:57216] app_config = AppConfig.create(entry), referer: <<url goes here>>/
[Thu Apr 23 11:15:23.804413 2015] [:error] [pid 15039] [client 172.16.75.13:57216] File "/usr/lib/python2.7/site-packages/django/apps/config.py", line 87, in create, referer: <<url goes here>>/
[Thu Apr 23 11:15:23.804624 2015] [:error] [pid 15039] [client 172.16.75.13:57216] module = import_module(entry), referer: <<url goes here>>/
[Thu Apr 23 11:15:23.804656 2015] [:error] [pid 15039] [client 172.16.75.13:57216] File "/usr/lib64/python2.7/importlib/__init__.py", line 37, in import_module, referer: <<url goes here>>/
[Thu Apr 23 11:15:23.804744 2015] [:error] [pid 15039] [client 172.16.75.13:57216] __import__(name), referer: <<url goes here>>/
[Thu Apr 23 11:15:23.804797 2015] [:error] [pid 15039] [client 172.16.75.13:57216] ImportError: No module named my_report, referer: <<url goes here>>/
这是 .wsgi 文件:
import os
import sys
from django.core.wsgi import get_wsgi_application
os.environ['DJANGO_SETTINGS_MODULE'] = 'settings'
path='/var/www/html/CoreRubrics/DjangoBackend/my_proj'
if path not in sys.path:
sys.path.append(path)
application = get_wsgi_application()
所以我尝试运行:
python /var/www/html/CoreRubrics/DjangoBackend/apache/django.wsgi
然后我收到此错误:
Traceback (most recent call last):
File "/var/www/html/CoreRubrics/DjangoBackend/apache/django.wsgi", line 12, in <module>
application = get_wsgi_application()
File "/usr/lib/python2.7/site-packages/django/core/wsgi.py", line 14, in get_wsgi_application
django.setup()
File "/usr/lib/python2.7/site-packages/django/__init__.py", line 21, in setup
apps.populate(settings.INSTALLED_APPS)
File "/usr/lib/python2.7/site-packages/django/apps/registry.py", line 85, in populate
app_config = AppConfig.create(entry)
File "/usr/lib/python2.7/site-packages/django/apps/config.py", line 87, in create
module = import_module(entry)
File "/usr/lib64/python2.7/importlib/__init__.py", line 37, in import_module
__import__(name)
ImportError: No module named my_report
这是我的settings.py
# Django settings for my_proj project.
from mongoengine import connect
connect(<<super secret DB stuff>>)
DEBUG = True
TEMPLATE_DEBUG = DEBUG
ADMINS = (
('William Karavites', 'willkara@oit.rutgers.edu'),
)
MANAGERS = ADMINS
#DATABASES = {
# 'default': {
# 'ENGINE': 'django.db.backends.', # Add 'postgresql_psycopg2', 'mysql', 'sqlite3' or 'oracle'.
#'NAME': '', # Or path to database file if using sqlite3.
# The following settings are not used with sqlite3:
#'USER': '',
#'PASSWORD': '',
#'HOST': '', # Empty for localhost through domain sockets or '127.0.0.1' for localhost through TCP.
#'PORT': '', # Set to empty string for default.
# }
#}
# Hosts/domain names that are valid for this site; required if DEBUG is False
# See https://docs.djangoproject.com/en/1.5/ref/settings/#allowed-hosts
ALLOWED_HOSTS = []
# Local time zone for this installation. Choices can be found here:
# http://en.wikipedia.org/wiki/List_of_tz_zones_by_name
# although not all choices may be available on all operating systems.
# In a Windows environment this must be set to your system time zone.
TIME_ZONE = 'America/New_York'
# Language code for this installation. All choices can be found here:
# http://www.i18nguy.com/unicode/language-identifiers.html
LANGUAGE_CODE = 'en-us'
SITE_ID = 1
# If you set this to False, Django will make some optimizations so as not
# to load the internationalization machinery.
USE_I18N = True
# If you set this to False, Django will not format dates, numbers and
# calendars according to the current locale.
USE_L10N = True
# If you set this to False, Django will not use timezone-aware datetimes.
USE_TZ = True
# Absolute filesystem path to the directory that will hold user-uploaded files.
# Example: "/var/www/example.com/media/"
MEDIA_ROOT = ''
# URL that handles the media served from MEDIA_ROOT. Make sure to use a
# trailing slash.
# Examples: "http://example.com/media/", "http://media.example.com/"
MEDIA_URL = ''
# Absolute path to the directory static files should be collected to.
# Don't put anything in this directory yourself; store your static files
# in apps' "static/" subdirectories and in STATICFILES_DIRS.
# Example: "/var/www/example.com/static/"
STATIC_ROOT = ''
# URL prefix for static files.
# Example: "http://example.com/static/", "http://static.example.com/"
STATIC_URL = '/static/'
# Additional locations of static files
STATICFILES_DIRS = (
# Put strings here, like "/home/html/static" or "C:/www/django/static".
# Always use forward slashes, even on Windows.
# Don't forget to use absolute paths, not relative paths.
)
# List of finder classes that know how to find static files in
# various locations.
STATICFILES_FINDERS = (
'django.contrib.staticfiles.finders.FileSystemFinder',
'django.contrib.staticfiles.finders.AppDirectoriesFinder',
# 'django.contrib.staticfiles.finders.DefaultStorageFinder',
)
# Make this unique, and don't share it with anybody.
SECRET_KEY = '<super secret secret>'
# List of callables that know how to import templates from various sources.
TEMPLATE_LOADERS = (
'django.template.loaders.filesystem.Loader',
'django.template.loaders.app_directories.Loader',
# 'django.template.loaders.eggs.Loader',
)
MIDDLEWARE_CLASSES = (
'django.middleware.common.CommonMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
#'django.contrib.auth.middleware.RemoteUserMiddleware',
# Uncomment the next line for simple clickjacking protection:
# 'django.middleware.clickjacking.XFrameOptionsMiddleware',
)
#AUTHENTICATION_BACKENDS = (
# 'django.contrib.auth.backends.RemoteUserBackend',
#)
ROOT_URLCONF = 'my_proj.urls'
# Python dotted path to the WSGI application used by Django's runserver.
WSGI_APPLICATION = 'my_proj.wsgi.application'
TEMPLATE_DIRS = (
# Put strings here, like "/home/html/django_templates" or "C:/www/django/templates".
# Always use forward slashes, even on Windows.
# Don't forget to use absolute paths, not relative paths.
)
INSTALLED_APPS = (
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.messages',
'django.contrib.staticfiles',
# Uncomment the next line to enable the admin:
# 'django.contrib.admin',
# Uncomment the next line to enable admin documentation:
'django.contrib.admindocs',
'mongoengine.django.mongo_auth',
'my_report',
)
AUTH_USER_MODEL = 'mongo_auth.MongoUser'
MONGOENGINE_USER_DOCUMENT = 'mongoengine.django.auth.User'
SESSION_ENGINE = 'mongoengine.django.sessions'
# A sample logging configuration. The only tangible logging
# performed by this configuration is to send an email to
# the site admins on every HTTP 500 error when DEBUG=False.
# See http://docs.djangoproject.com/en/dev/topics/logging for
# more details on how to customize your logging configuration.
LOGGING = {
'version': 1,
'disable_existing_loggers': False,
'filters': {
'require_debug_false': {
'()': 'django.utils.log.RequireDebugFalse'
}
},
'handlers': {
'mail_admins': {
'level': 'ERROR',
'filters': ['require_debug_false'],
'class': 'django.utils.log.AdminEmailHandler'
}
},
'loggers': {
'django.request': {
'handlers': ['mail_admins'],
'level': 'ERROR',
'propagate': True,
},
}
}
Aaaaaa,以防万一,这是我的站点 apache .conf 文件:
#modified from anaylitics:/etc/httpd/conf.d/apache.conf
#<Directory /home/kimhuang/my_proj/apache>
#Order deny,allow
#Allow from all
#</Directory>
#WSGIPythonHome /home/kimhuang/my_proj_env
WSGIPythonPath /var/www/html/CoreRubrics/DjangoBackend/my_proj/:/var/www/html/CoreRubrics/DjangoBackend/my_report/
#WSGIScriptAlias /cr /home/kimhuang/my_proj/apache/django.wsgi
<VirtualHost <<ip>>>
ServerName <<url>>
ServerAlias <<url>>
<Location "/">
Order Allow,Deny
Allow from all
</Location>
DocumentRoot /var/www/html/CoreRubrics/FrontEnd
WSGIScriptAlias /corerubric/cr /var/www/html/CoreRubrics/DjangoBackend/apache/django.wsgi
ErrorLog logs/corerubrics_error_log
LogLevel debug
CustomLog logs/corerubrics_access_log combined
<Directory /var/www/html/CoreRubrics/DjangoBackend/apache/>
<Files django.wsgi>
Require all granted
</Files>
</Directory>
</VirtualHost>
最佳答案
my_report
应用程序不在项目路径上。
更改 wsgi 文件中的以下行:
os.environ['DJANGO_SETTINGS_MODULE'] = 'my_proj.settings'
path='/var/www/html/CoreRubrics/DjangoBackend/'
您可能应该阅读有关正确项目结构的信息,因此这里有一些资源:
关于python - Django/Apache 设置给我一个 'module not found' 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29827930/
我正在处理一组标记为 160 个组的 173k 点。我想通过合并最接近的(到 9 或 10 个组)来减少组/集群的数量。我搜索过 sklearn 或类似的库,但没有成功。 我猜它只是通过 knn 聚类
我有一个扁平数字列表,这些数字逻辑上以 3 为一组,其中每个三元组是 (number, __ignored, flag[0 or 1]),例如: [7,56,1, 8,0,0, 2,0,0, 6,1,
我正在使用 pipenv 来管理我的包。我想编写一个 python 脚本来调用另一个使用不同虚拟环境(VE)的 python 脚本。 如何运行使用 VE1 的 python 脚本 1 并调用另一个 p
假设我有一个文件 script.py 位于 path = "foo/bar/script.py"。我正在寻找一种在 Python 中通过函数 execute_script() 从我的主要 Python
这听起来像是谜语或笑话,但实际上我还没有找到这个问题的答案。 问题到底是什么? 我想运行 2 个脚本。在第一个脚本中,我调用另一个脚本,但我希望它们继续并行,而不是在两个单独的线程中。主要是我不希望第
我有一个带有 python 2.5.5 的软件。我想发送一个命令,该命令将在 python 2.7.5 中启动一个脚本,然后继续执行该脚本。 我试过用 #!python2.7.5 和http://re
我在 python 命令行(使用 python 2.7)中,并尝试运行 Python 脚本。我的操作系统是 Windows 7。我已将我的目录设置为包含我所有脚本的文件夹,使用: os.chdir("
剧透:部分解决(见最后)。 以下是使用 Python 嵌入的代码示例: #include int main(int argc, char** argv) { Py_SetPythonHome
假设我有以下列表,对应于及时的股票价格: prices = [1, 3, 7, 10, 9, 8, 5, 3, 6, 8, 12, 9, 6, 10, 13, 8, 4, 11] 我想确定以下总体上最
所以我试图在选择某个单选按钮时更改此框架的背景。 我的框架位于一个类中,并且单选按钮的功能位于该类之外。 (这样我就可以在所有其他框架上调用它们。) 问题是每当我选择单选按钮时都会出现以下错误: co
我正在尝试将字符串与 python 中的正则表达式进行比较,如下所示, #!/usr/bin/env python3 import re str1 = "Expecting property name
考虑以下原型(prototype) Boost.Python 模块,该模块从单独的 C++ 头文件中引入类“D”。 /* file: a/b.cpp */ BOOST_PYTHON_MODULE(c)
如何编写一个程序来“识别函数调用的行号?” python 检查模块提供了定位行号的选项,但是, def di(): return inspect.currentframe().f_back.f_l
我已经使用 macports 安装了 Python 2.7,并且由于我的 $PATH 变量,这就是我输入 $ python 时得到的变量。然而,virtualenv 默认使用 Python 2.6,除
我只想问如何加快 python 上的 re.search 速度。 我有一个很长的字符串行,长度为 176861(即带有一些符号的字母数字字符),我使用此函数测试了该行以进行研究: def getExe
list1= [u'%app%%General%%Council%', u'%people%', u'%people%%Regional%%Council%%Mandate%', u'%ppp%%Ge
这个问题在这里已经有了答案: Is it Pythonic to use list comprehensions for just side effects? (7 个答案) 关闭 4 个月前。 告
我想用 Python 将两个列表组合成一个列表,方法如下: a = [1,1,1,2,2,2,3,3,3,3] b= ["Sun", "is", "bright", "June","and" ,"Ju
我正在运行带有最新 Boost 发行版 (1.55.0) 的 Mac OS X 10.8.4 (Darwin 12.4.0)。我正在按照说明 here构建包含在我的发行版中的教程 Boost-Pyth
学习 Python,我正在尝试制作一个没有任何第 3 方库的网络抓取工具,这样过程对我来说并没有简化,而且我知道我在做什么。我浏览了一些在线资源,但所有这些都让我对某些事情感到困惑。 html 看起来
我是一名优秀的程序员,十分优秀!