问题 Django - 没有名为app的模块


我一直试图用django工作来编写一个应用程序 - 但它根本不起作用。我已经工作了一段时间 - 它正在完美地开发dev-server。但我无法投入生产环境(apahce)。

我的项目名称是apstat,应用程序名称是基本的。

我尝试按如下方式访问它

大段引用    HTTP://主机名/ apstat

但它显示以下错误:

MOD_PYTHON ERROR

ProcessId:      6002
Interpreter:    'domU-12-31-39-06-DD-F4.compute-1.internal'

ServerName:     'domU-12-31-39-06-DD-F4.compute-1.internal'
DocumentRoot:   '/home/ubuntu/server/'

URI:            '/apstat/'
Location:       '/apstat'
Directory:      None
Filename:       '/home/ubuntu/server/apstat/'
PathInfo:       ''

Phase:          'PythonHandler'
Handler:        'django.core.handlers.modpython'

Traceback (most recent call last):

  File "/usr/lib/python2.6/dist-packages/mod_python/importer.py", line 1537, in HandlerDispatch
    default=default_handler, arg=req, silent=hlist.silent)

  File "/usr/lib/python2.6/dist-packages/mod_python/importer.py", line 1229, in _process_target
    result = _execute_target(config, req, object, arg)

  File "/usr/lib/python2.6/dist-packages/mod_python/importer.py", line 1128, in _execute_target
    result = object(arg)

  File "/usr/lib/pymodules/python2.6/django/core/handlers/modpython.py", line 228, in handler
    return ModPythonHandler()(req)

  File "/usr/lib/pymodules/python2.6/django/core/handlers/modpython.py", line 201, in __call__
    response = self.get_response(request)

  File "/usr/lib/pymodules/python2.6/django/core/handlers/base.py", line 134, in get_response
    return self.handle_uncaught_exception(request, resolver, exc_info)

  File "/usr/lib/pymodules/python2.6/django/core/handlers/base.py", line 154, in handle_uncaught_exception
    return debug.technical_500_response(request, *exc_info)

  File "/usr/lib/pymodules/python2.6/django/views/debug.py", line 40, in technical_500_response
    html = reporter.get_traceback_html()

  File "/usr/lib/pymodules/python2.6/django/views/debug.py", line 114, in get_traceback_html
    return t.render(c)

  File "/usr/lib/pymodules/python2.6/django/template/__init__.py", line 178, in render
    return self.nodelist.render(context)

  File "/usr/lib/pymodules/python2.6/django/template/__init__.py", line 779, in render
    bits.append(self.render_node(node, context))

  File "/usr/lib/pymodules/python2.6/django/template/debug.py", line 81, in render_node
    raise wrapped

TemplateSyntaxError: Caught an exception while rendering: No module named basic

Original Traceback (most recent call last):
  File "/usr/lib/pymodules/python2.6/django/template/debug.py", line 71, in render_node
    result = node.render(context)
  File "/usr/lib/pymodules/python2.6/django/template/debug.py", line 87, in render
    output = force_unicode(self.filter_expression.resolve(context))
  File "/usr/lib/pymodules/python2.6/django/template/__init__.py", line 572, in resolve
    new_obj = func(obj, *arg_vals)
  File "/usr/lib/pymodules/python2.6/django/template/defaultfilters.py", line 687, in date
    return format(value, arg)
  File "/usr/lib/pymodules/python2.6/django/utils/dateformat.py", line 269, in format
    return df.format(format_string)
  File "/usr/lib/pymodules/python2.6/django/utils/dateformat.py", line 30, in format
    pieces.append(force_unicode(getattr(self, piece)()))
  File "/usr/lib/pymodules/python2.6/django/utils/dateformat.py", line 175, in r
    return self.format('D, j M Y H:i:s O')
  File "/usr/lib/pymodules/python2.6/django/utils/dateformat.py", line 30, in format
    pieces.append(force_unicode(getattr(self, piece)()))
  File "/usr/lib/pymodules/python2.6/django/utils/encoding.py", line 71, in force_unicode
    s = unicode(s)
  File "/usr/lib/pymodules/python2.6/django/utils/functional.py", line 201, in __unicode_cast
    return self.__func(*self.__args, **self.__kw)
  File "/usr/lib/pymodules/python2.6/django/utils/translation/__init__.py", line 62, in ugettext
    return real_ugettext(message)
  File "/usr/lib/pymodules/python2.6/django/utils/translation/trans_real.py", line 286, in ugettext
    return do_translate(message, 'ugettext')
  File "/usr/lib/pymodules/python2.6/django/utils/translation/trans_real.py", line 276, in do_translate
    _default = translation(settings.LANGUAGE_CODE)
  File "/usr/lib/pymodules/python2.6/django/utils/translation/trans_real.py", line 194, in translation
    default_translation = _fetch(settings.LANGUAGE_CODE)
  File "/usr/lib/pymodules/python2.6/django/utils/translation/trans_real.py", line 180, in _fetch
    app = import_module(appname)
  File "/usr/lib/pymodules/python2.6/django/utils/importlib.py", line 35, in import_module
    __import__(name)
ImportError: No module named basic

我的settings.py如下:

INSTALLED_APPS = (
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.sites',
    'apstat.basic',
    'django.contrib.admin',
)

如果我删除apstat.basic,它会通过,但这不是一个解决方案。这是我在apache做的事情吗?

我的apache - 设置是 -

<VirtualHost *:80>
        ServerAdmin webmaster@localhost

        DocumentRoot /home/ubuntu/server/
        <Directory />
                Options None
                AllowOverride None
        </Directory>

        <Directory /home/ubuntu/server/apstat>
                AllowOverride None
                Order allow,deny
                allow from all
        </Directory>

        <Location "/apstat">
                SetHandler python-program
                PythonHandler django.core.handlers.modpython
                SetEnv DJANGO_SETTINGS_MODULE apstat.settings
                PythonOption django.root /home/ubuntu/server/
                PythonDebug On
                PythonPath "['/home/ubuntu/server/'] + sys.path"
        </Location>

</VirtualHost>

我现在已经坐了一天多了。如果有人可以帮助我,那将是非常好的。


3458
2018-03-28 09:07


起源

发现了这个问题。内 在里面.py,我正在做一些初始化。在开发服务器中它工作,但在Apache,一些权限问题导致它失败。 Django吃错误,所以这是不明显的。 - Koran


答案:


你有基本的吗? __init__.py


12
2018-03-28 11:34



是。实际上那就是问题所在。它有初始化日志等的init.py。有一些问题与methinks权限,导致它出错。所以,当我使用dev服务器进行测试时,它工作正常,但在apache中它失败了。 Django吃掉实际的错误日志;-( - Koran
您可以在apache错误日志中找到它们。 - Lakshman Prasad


您需要确保项目在您的项目中 PYTHONPATH。也许尝试输出 sys.path 设置文件顶部的变量:

import sys
print sys.path

如果这不起作用 mod_python 尝试将其写入文件:

import sys
file('/tmp/mysyspath.txt', 'w').write(repr(sys.path))

但即使这样可行,也只是一个简短的警告: django社区不鼓励使用它 mod_python。它不再由其创建者维护,也不是部署django项目的最佳解决方案。请尝试 mod_wsgi 如果它在您的服务器上可用。


4
2017-07-27 08:29





通常会添加项目目录 sys.path 然后直接使用应用程序名称 INSTALLED_APPS 以及其他应用程序中的导入。试一试。


0
2018-03-28 09:15



我试过了,但无济于事。 - Koran