简体   繁体   English

错误:django 1.3.1 + python 2.6 中没有名为 staticfiles 的模块? 怎么了

[英]Error: No module named staticfiles in django 1.3.1 + python 2.6? what's wrong

I didn't worked on the django project for somedays and now I return and I can't work on it.我有几天没有在 django 项目上工作,现在我回来了,我无法继续工作。 When I debug or run in eclipse aptana I get the "Error: No module named staticfiles" error.当我在 eclipse aptana 中调试或运行时,出现“错误:没有名为静态文件的模块”错误。

  • I have even updated aptana to today's updates and no luck.我什至将 aptana 更新为今天的更新,但没有运气。
  • I have uninstalled the django, delete all files and reinstall.我已经卸载了 django,删除了所有文件并重新安装。
  • If I import django with python in cmd (on windows) it is in the place I expect to be如果我在 cmd ( 在 Windows 上) 中使用 python 导入 django 它就在我期望的地方

But if I delete the "'django.contrib.staticfiles'," string in the "INSTALLED_APPS" from settings.py everything works fine but I have no access to the static files, as expected..但是,如果我从 settings.py 中删除“INSTALLED_APPS”中的“'django.contrib.staticfiles'”字符串,一切正常,但我无法访问静态文件,正如预期的那样..

In those days I have installed Google app engine + python 2.5;那些天我安装了谷歌应用引擎+python 2.5; can this be the problem and how to solve?这可能是问题以及如何解决?

thank you very much*非常感谢你*

Here are the steps I'd take to find out the problem:以下是我为找出问题而采取的步骤:

  • verify that it's working correctly in the command-line (cmd.exe in windows) - just to remove the issues associated with Aptana.验证它在命令行(Windows 中的 cmd.exe)中是否正常工作 - 只是为了消除与 Aptana 相关的问题。 You need to do something like: C:\\Path\\to\\Python2.6\\python.exe manage.py runserver (NB: choose any management command that will check your settings.py).您需要执行以下操作:C:\\Path\\to\\Python2.6\\python.exe manage.py runserver(注意:选择任何将检查您的 settings.py 的管理命令)。 If this gives the same error, then you haven't got Django 1.3.1 installed in Python2.6 (you could install it, or you could set up a fresh virtualenv, see below)如果这给出了同样的错误,那么你还没有在 Python2.6 中安装 Django 1.3.1(你可以安装它,或者你可以设置一个新的 virtualenv,见下文)
  • once you've got it working in the command line, you just have to make sure that aptana is using the correct interpreter path.一旦你让它在命令行中工作,你只需要确保 aptana 使用正确的解释器路径。 You need to check that you've defined it correctly (in your global preferences (the workspace settings) -- pydev python interpreter) and then are using it in the specific project -- (check the project settings that it is using the python interpreter you just defined )您需要检查您是否正确定义了它(在您的全局首选项(工作区设置)--pydev python 解释器中),然后在特定项目中使用它--(检查它使用 python 解释器的项目设置你刚刚定义)
  • NB: Django 1.3.1 can use python2.5, but not next version of django注意:Django 1.3.1 可以使用 python2.5,但不能使用下一版本的 django

Here is how I would avoid this in future:以下是我将来避免这种情况的方法:

  • use virtualenv[1] to avoid being dependent on the arbitrary nature of your installation history (once you've installed virtualenv in ANY version of python you can then specify which python when you set up the virtualenv: virtualenv -p C:\\Path\\to\\Python2.6\\python.exe ).使用 virtualenv[1] 避免依赖于安装历史的任意性质(一旦你在任何版本的 python 中安装了 virtualenv,你就可以在设置 virtualenv 时指定哪个 python: virtualenv -p C:\\Path\\ to\\Python2.6\\python.exe )。
  • use virtualenv --no-site-packages to ensure you have no dependencies locally使用 virtualenv --no-site-packages 确保您在本地没有依赖项
  • use pip[2] to install all your python packages (problems may occur with packages with binary content - use easy_install for those)使用 pip[2] 安装所有的 python 包(带有二进制内容的包可能会出现问题 - 使用 easy_install)
  • use pip freeze > requirements.txt to record your dependencies (and add this file into your source code control)使用 pip freeze > requirements.txt 记录您的依赖项(并将此文件添加到您的源代码控制中)

[1] http://pypi.python.org/pypi/virtualenv [1] http://pypi.python.org/pypi/virtualenv

[2] http://pypi.python.org/pypi/pip [2] http://pypi.python.org/pypi/pip

NB pip and easy_install are automatically installed into your new virtualenv NB pip 和 easy_install 会自动安装到你的新 virtualenv 中

在新版Django中使用{% load static %}代替{% load staticfiles %} ,加载静态文件的语法发生了变化

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM