0

我需要问一下,因为我是从 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 以正确执行代码?
4

2 回答 2

0

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

于 2013-02-07T12:29:34.817 回答
0

我认为它现在有点过时了,但我强烈建议您阅读Djangobook示例。它将解释如何正确设置 Django,并为如何使用它提供一个很好的基础。

于 2013-02-07T12:47:31.330 回答