第一步Django错误

时间:2013-02-07 12:19:21

标签: python django eclipse pydev

我需要问一下,因为我是从Django开始的,我不可能继续学习我正在学习的教程。我刚刚完成了Python课程,我知道python的基础知识。情况是我已经在我的mac中安装了Django并且没关系,因为当我在IDLE中这样做时

import django
print django.VERSION

它在IDLE中没有错误是一个很好的答案(我用来编写python代码的软件)。但是当我在终端执行命令时:

python manage.py runserver

它引发了这个错误:

Traceback (most recent call last):
  File "/Library/Frameworks/Python.framework/Versions/Current/bin/django-admin.py", line 5, in <module>
    management.execute_from_command_line()
  File "/Library/Frameworks/Python.framework/Versions/7.3/lib/python2.7/site-packages/django/core/management/__init__.py", line 443, in execute_from_command_line
    utility.execute()
  File "/Library/Frameworks/Python.framework/Versions/7.3/lib/python2.7/site-packages/django/core/management/__init__.py", line 382, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/Library/Frameworks/Python.framework/Versions/7.3/lib/python2.7/site-packages/django/core/management/__init__.py", line 261, in fetch_command
    klass = load_command_class(app_name, subcommand)
  File "/Library/Frameworks/Python.framework/Versions/7.3/lib/python2.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/Frameworks/Python.framework/Versions/7.3/lib/python2.7/site-packages/django/utils/importlib.py", line 35, in import_module
    __import__(name)
  File "/Library/Frameworks/Python.framework/Versions/7.3/lib/python2.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/Frameworks/Python.framework/Versions/7.3/lib/python2.7/site-packages/django/core/servers/basehttp.py", line 26, in <module>
    from django.views import static
  File "/Library/Frameworks/Python.framework/Versions/7.3/lib/python2.7/site-packages/django/views/static.py", line 95, in <module>
    template_translatable = ugettext_noop(u"Index of %(directory)s")
  File "/Library/Frameworks/Python.framework/Versions/7.3/lib/python2.7/site-packages/django/utils/translation/__init__.py", line 75, in gettext_noop
    return _trans.gettext_noop(message)
  File "/Library/Frameworks/Python.framework/Versions/7.3/lib/python2.7/site-packages/django/utils/translation/__init__.py", line 48, in __getattr__
    if settings.USE_I18N:
  File "/Library/Frameworks/Python.framework/Versions/7.3/lib/python2.7/site-packages/django/utils/functional.py", line 184, in inner
    self._setup()
  File "/Library/Frameworks/Python.framework/Versions/7.3/lib/python2.7/site-packages/django/conf/__init__.py", line 40, in _setup
    raise ImportError("Settings cannot be imported, because environment variable %s is undefined." % ENVIRONMENT_VARIABLE)
ImportError: Settings cannot be imported, because environment variable DJANGO_SETTINGS_MODULE is undefined.

我也想问你一些问题:

  • 我可以使用XAMPP而不是Django吗?怎么样?
  • Django究竟用于什么?
  • 我在Eclipse中安装了PyDev。如何设置Django正确执行代码?

2 个答案:

答案 0 :(得分:0)

在目标目录下调用命令django-admin startproject xxx。您可以获得三个.py文件: setting.py urls.py manage.py 。您可以执行python manage.py runserver命令

答案 1 :(得分:0)

我认为它现在略显过时,但我认真地建议您浏览Djangobook示例。它将解释如何正确设置Django,并为如何使用它提供一个很好的基础。