【问题标题】:Heroku/Django project not working locally, maybe a path issueHeroku/Django 项目无法在本地运行,可能是路径问题
【发布时间】:2014-06-14 19:13:04
【问题描述】:

我在一个从 heroku 克隆的项目文件夹中。在我运行的文件夹中

$ python manage.py runserver
Traceback (most recent call last):
  File "manage.py", line 10, in <module>
    execute_from_command_line(sys.argv)
  File "/Library/Python/2.7/site-packages/django/core/management/__init__.py", line 443, in execute_from_command_line
    utility.execute()
  File "/Library/Python/2.7/site-packages/django/core/management/__init__.py", line 382, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/Library/Python/2.7/site-packages/django/core/management/__init__.py", line 261, in fetch_command
    klass = load_command_class(app_name, subcommand)
  File "/Library/Python/2.7/site-packages/django/core/management/__init__.py", line 69, in load_command_class
    module = import_module('%s.management.commands.%s' % (app_name, name))
  File "/Library/Python/2.7/site-packages/django/utils/importlib.py", line 35, in import_module
    __import__(name)
  File "/Library/Python/2.7/site-packages/django/core/management/commands/runserver.py", line 8, in <module>
    from django.core.servers.basehttp import AdminMediaHandler, run, WSGIServerException, get_internal_wsgi_application
  File "/Library/Python/2.7/site-packages/django/core/servers/basehttp.py", line 26, in <module>
    from django.views import static
  File "/Library/Python/2.7/site-packages/django/views/static.py", line 95, in <module>
    template_translatable = ugettext_noop(u"Index of %(directory)s")
  File "/Library/Python/2.7/site-packages/django/utils/translation/__init__.py", line 75, in gettext_noop
    return _trans.gettext_noop(message)
  File "/Library/Python/2.7/site-packages/django/utils/translation/__init__.py", line 48, in __getattr__
    if settings.USE_I18N:
  File "/Library/Python/2.7/site-packages/django/utils/functional.py", line 184, in inner
    self._setup()
  File "/Library/Python/2.7/site-packages/django/conf/__init__.py", line 42, in _setup
    self._wrapped = Settings(settings_module)
  File "/Library/Python/2.7/site-packages/django/conf/__init__.py", line 95, in __init__
    raise ImportError("Could not import settings '%s' (Is it on sys.path?): %s" % (self.SETTINGS_MODULE, e))
ImportError: Could not import settings 'pinpoint.settings' (Is it on sys.path?): No module named pinpoint.settings

并得到这个 ^ 错误。

在网上搜索后,有人建议我“为我的路径添加精确定位”。不完全确定如何做到这一点,但我认为我必须先检查我的路径是否有它。所以我跑了

$ python
Python 2.7.5 (default, Aug 25 2013, 00:04:04) 
[GCC 4.2.1 Compatible Apple LLVM 5.0 (clang-500.0.68)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> for path in sys.path: print path
... 

/Library/Python/2.7/site-packages/pip-1.5.4-py2.7.egg
/Library/Python/2.7/site-packages/Gimbpy-1.0-py2.7.egg
/Library/Python/2.7/site-packages/requests-2.2.1-py2.7.egg
/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python27.zip
/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7
/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-darwin
/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac
/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac/lib-scriptpackages
/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python
/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-tk
/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-old
/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-dynload
/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/PyObjC
/Library/Python/2.7/site-packages

在 ^ 中,我没有看到项目文件夹,也没有看到嵌套在项目文件夹内的文件夹精确位置。唔?我从这里去哪里。我正在尝试在本地运行我的项目,以便在提交之前进行测试。知道我能做些什么来解决这个问题吗?我对整个“添加到路径”的事情很陌生。

【问题讨论】:

    标签: python django heroku


    【解决方案1】:

    首先在 Second command 中查找 Paths 列表时,您必须运行“python manage.py shell”而不是“python”,因为前者将打开特定于您的项目的 python。

    注意:ma​​nage.py 所在的目录路径会自动添加到路径中。

    附加到路径很简单,即。

    import sys
    sys.path.append(<new_path>)
    

    但是在添加任何路径之前,我会建议您在 manage.py 文件中提供 settings 文件的正确路径。它应该与你的 manage.py 所在的目录相关(以便系统可以选择它)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-03-14
      • 2015-07-29
      • 1970-01-01
      • 1970-01-01
      • 2018-01-20
      • 2012-07-13
      • 2022-07-06
      • 1970-01-01
      相关资源
      最近更新 更多