让 Django 与 Eclipse 一起工作
我是 python 和 django 的新手,但想开始学习一些教程。我安装了python,然后是django,然后是eclipse的pydev插件。我创建了一个新的 django 项目并尝试运行它。在 Eclipse 中,我使用参数 runserver 设置了 manage.py 的运行配置,它说“验证模型”,但从未说过任何其他内容。
我也尝试通过命令行运行,但遇到了一些我在 eclipse 中没有看到的错误:
C:\Users\JP\workspace\mysite\src\mysite>python manage.py runserver
Validating models...
Unhandled exception in thread started by <function inner_run at 0x02851E30>
Traceback (most recent call last):
File "c:\Python27\lib\site-packages\django\core\management\commands\runserver.
py", line 48, in inner_run
self.validate(display_num_errors=True)
File "c:\Python27\lib\site-packages\django\core\management\base.py", line 245,
in validate
num_errors = get_validation_errors(s, app)
File "c:\Python27\lib\site-packages\django\core\management\validation.py", lin
e 22, in get_validation_errors
from django.db import models, connection
File "c:\Python27\lib\site-packages\django\db\__init__.py", line 75, in <modul
e>
connection = connections[DEFAULT_DB_ALIAS]
File "c:\Python27\lib\site-packages\django\db\utils.py", line 91, in __getitem
__
backend = load_backend(db['ENGINE'])
File "c:\Python27\lib\site-packages\django\db\utils.py", line 32, 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 14
, in <module>
raise ImproperlyConfigured("Error loading MySQLdb module: %s" % e)
django.core.exceptions.ImproperlyConfigured: Error loading MySQLdb module: No mo
dule named MySQLdb
我认为它与我的 sql 设置有关,但我不确定,因为它是一个空白项目,而且我还没有编写任何内容代码还没。我更关心为什么日食中什么也没有出现。
I'm new to python and django but wanted to start following some tutorials. I installed python, then django, and then the pydev plugin for eclipse. I created a new django project and tried running it. In eclipse I set up a run configuration for manage.py with argument runserver and it said "Validating Models" but never said anything else.
I tried running via command line also but got some errors that I didn't see in eclipse:
C:\Users\JP\workspace\mysite\src\mysite>python manage.py runserver
Validating models...
Unhandled exception in thread started by <function inner_run at 0x02851E30>
Traceback (most recent call last):
File "c:\Python27\lib\site-packages\django\core\management\commands\runserver.
py", line 48, in inner_run
self.validate(display_num_errors=True)
File "c:\Python27\lib\site-packages\django\core\management\base.py", line 245,
in validate
num_errors = get_validation_errors(s, app)
File "c:\Python27\lib\site-packages\django\core\management\validation.py", lin
e 22, in get_validation_errors
from django.db import models, connection
File "c:\Python27\lib\site-packages\django\db\__init__.py", line 75, in <modul
e>
connection = connections[DEFAULT_DB_ALIAS]
File "c:\Python27\lib\site-packages\django\db\utils.py", line 91, in __getitem
__
backend = load_backend(db['ENGINE'])
File "c:\Python27\lib\site-packages\django\db\utils.py", line 32, 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 14
, in <module>
raise ImproperlyConfigured("Error loading MySQLdb module: %s" % e)
django.core.exceptions.ImproperlyConfigured: Error loading MySQLdb module: No mo
dule named MySQLdb
I assume it has something to do with my sql setup, but I'm not sure since it's a blank project and I haven't written any code yet. I'm more concerned with why nothing showed up in eclipse.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我自己才刚刚开始。显然,除了标准 MySQL 安装之外,您还需要使用 MySQLdb 插件(抱歉,如果这不是正确的术语)。这样Python就可以与MySQL进行通信。
I'm just starting myself. Apparently there's a MySQLdb plugin (sorry if that's not the right term) that you need to use in addition to a standard MySQL install. This is so Python can communicate with MySQL.
听起来您需要将该模块包含在 Eclipse 系统 PYTHONPATH 中。
转到 Windows ->偏好->派德夫 ->解释器——Python。
选择所需的 python 解释器(如果您有虚拟环境)后,将您的 MySQL Egg 和所有其他依赖项包含在您的库中。
It sounds like that you need to include the module in Eclipse System PYTHONPATH.
Go to Windows -> Preference -> Pydev -> Interpreter - Python.
After Select your desired python interpreters (if you have a virtual env), include your MySQL egg and all your other dependencies in your library.
看来你没有安装mysql。如果你只是尝试 django,你可以使用 python 附带的 sqlite。您可以在 settings.py 文件中更改数据库后端。
It seems you don't have mysql installed. If you're only trying out django, you could use sqlite which ships with python. You can change the db backend in your settings.py file.