0

我决定尝试用 django 在 python 上开发,而 python 对我来说是新的。

[我使用的是 Windows 7 64 位]

然后,我安装了 python 2.7,添加了 C:\Python27\;C:\Python27\Scripts; 到 PATH 变量。接下来,我安装了 Eclipse Classic(最新版本)并安装了 PyDev 和 Django。

我在 Eclipse 上创建了我的第一个项目作为 Django 项目,但无法运行它。我正在尝试(右键单击我的项目)-> 运行方式-> PyDev:Django,并且我有以下控制台日志:

Validating models...

Traceback (most recent call last):   File "C:\Users\Matan\workspace\FirstSample\manage.py", line 10, in <module>
    execute_from_command_line(sys.argv)   File "C:\Python27\Lib\site-packages\django\core\management\__init__.py", line 443, in execute_from_command_line
    utility.execute()   File "C:\Python27\Lib\site-packages\django\core\management\__init__.py", line 382, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)   File "C:\Python27\Lib\site-packages\django\core\management\base.py", line 196, in run_from_argv
    self.execute(*args, **options.__dict__)   File "C:\Python27\Lib\site-packages\django\core\management\base.py", line 232, in execute
    output = self.handle(*args, **options)   File "C:\Python27\Lib\site-packages\django\core\management\commands\runserver.py", line 69, in handle
    self.run(*args, **options)   File "C:\Python27\Lib\site-packages\django\core\management\commands\runserver.py", line 80, in run

而这样的例子不胜枚举...

所以我尝试使用 python 控制台运行该项目,使用:

import Django

manage.py runserver

我有以下语法错误:

File "<stdin>", line 1
  manage.py runserver
                    ^ SyntaxError: invalid syntax

运行我的项目有什么问题?我该如何解决这个问题?

谢谢。

编辑:尝试使用以下命令运行项目后:

python manage.py runserver on the project directory, i receive the following traceback log: Validating models...

Unhandled exception in thread started by <bound method Command.inner_run of <dja ngo.contrib.staticfiles.management.commands.runserver.Command object at 0x000000 0002688748>> Traceback (most recent call last):   File "C:\Python27\lib\site-packages\django\core\management\commands\runserver. py", line 91, in inner_run
    self.validate(display_num_errors=True)   File "C:\Python27\lib\site-packages\django\core\management\base.py", line 266,  in validate
    num_errors = get_validation_errors(s, app)   File "C:\Python27\lib\site-packages\django\core\management\validation.py", lin e 23, in get_validation_errors
    from django.db import models, connection   File "C:\Python27\lib\site-packages\django\db\__init__.py", line 40, in <modul e>
    backend = load_backend(connection.settings_dict['ENGINE'])   File "C:\Python27\lib\site-packages\django\db\__init__.py", line 34, in
__geta ttr__
    return getattr(connections[DEFAULT_DB_ALIAS], item)   File "C:\Python27\lib\site-packages\django\db\utils.py", line 92, in
__getitem
__
    backend = load_backend(db['ENGINE'])   File "C:\Python27\lib\site-packages\django\db\utils.py", line 24, in load_back end
    return import_module('.base', backend_name)   File "C:\Python27\lib\site-packages\django\utils\importlib.py", line 35, in im port_module
    __import__(name)   File "C:\Python27\lib\site-packages\django\db\backends\mysql\base.py", line 16 , in <module>
    raise ImproperlyConfigured("Error loading MySQLdb module: %s" % e) django.core.exceptions.ImproperlyConfigured: Error loading MySQLdb module: No mo dule named MySQLdb
4

3 回答 3

1

下载适用于 Windows 的预编译python-mysql 包,安装它,然后再次运行该命令。

当你在那里时,如果你还没有安装setuptools ,你也可以安装。

于 2012-05-04T00:17:10.730 回答
0

您必须在项目目录中才能运行 python manage.py runserver 命令。您还需要 (1) 设置 PYTHONPATH 环境变量以包含您的项目目录的目录和 (2) 将 DJANGO_SETTINGS_MODULE 环境变量设置为yourproject.settings

如果你做对了,你应该能够去一个不相关的目录(即不是你的项目目录)并在 python shell 中执行以下导入:

c:\temp> python
...
>>> from django.conf import settings

导入的设置模块应该是您项目目录中的那个...

于 2012-05-03T19:38:41.687 回答
0

加载 MySQLdb 模块时出错:没有名为 MySQLdb 的模块

您已经为 MySQL 配置了设置,但尚未安装MySQL-python

pip install MySQL-python
于 2012-05-03T19:47:12.417 回答