对于这个问题已经有了一些很好的答案,但是现在它们已经过时了。
我已经能够安装模块,但是“ python manage.py runserver”失败,
iMac:myproject drhoden$ python manage.py runserver
Validating models...
Unhandled exception in thread started by <function inner_run at 0x10496f0>
Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/django/core/management/commands/runserver.py", line 48, in inner_run
self.validate(display_num_errors=True)
File "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/django/core/management/base.py", line 249, in validate
num_errors = get_validation_errors(s, app)
File "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/django/core/management/validation.py", line 22, in get_validation_errors
from django.db import models, connection
File "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/django/db/__init__.py", line 41, in <module>
backend = load_backend(settings.DATABASE_ENGINE)
File "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/django/db/__init__.py", line 17, in load_backend
return import_module('.base', 'django.db.backends.%s' % backend_name)
File "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/django/utils/importlib.py", line 35, in import_module
__import__(name)
File "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/django/db/backends/mysql/base.py", line 13, in <module>
raise ImproperlyConfigured("Error loading MySQLdb module: %s" % e)
django.core.exceptions.ImproperlyConfigured: Error loading MySQLdb module: dynamic module does not define init function (init_mysql)
^CiMac:segisys drhoden$
同样,从python shell:
iMac:myproject drhoden$ python
Python 2.6.4 (r264:75821M, Oct 27 2009, 19:48:32)
[GCC 4.0.1 (Apple Inc. build 5493)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import MySQLdb
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "build/bdist.macosx-10.3-fat/egg/MySQLdb/__init__.py", line 19, in <module>
File "build/bdist.macosx-10.3-fat/egg/_mysql.py", line 7, in <module>
File "build/bdist.macosx-10.3-fat/egg/_mysql.py", line 6, in __bootstrap__
ImportError: dynamic module does not define init function (init_mysql)
>>>
使用MySQL-python-1.2.3c1和setuptools-0.6c11-py2.6.egg
任何帮助,将不胜感激。
我最终解决了自己的问题,当然,我从许多已读过的帖子,博客和邮件日志中获得了潜意识和有意识的帮助。如果我记得的话,我会提供链接。
简而言之,我使用MacPorts重新安装了一切。
编辑〜/ .bash_profile并注释掉对$ {PATH}的所有先前修改之后,我下载了Snow Leopard的dmg并完成了安装过程。
然后打开终端并运行自我更新。
sudo port selfupdate
sudo port install python26
第二部分,安装Python 2.6,花费了很多时间。但是完成后,提示我以下内容:
To fully complete your installation and make python 2.6 the default, please run
sudo port install python_select
sudo python_select python26
我都做了,他们很快就完成了。
我忘了提一下“端口搜索”命令有多方便。我搜索了“ mysql”,并且类似地找到了“安装”后要键入的内容。但是我着手重新安装MySQL的客户端和服务器。也许我以相反的顺序进行了操作,但是最终结果还是不错的。
sudo port install mysql5
...
---> Installing mysql5 @5.1.41_0
The MySQL client has been installed.
If you also want a MySQL server, install the mysql5-server port.
很自然地:
sudo port install mysql5-server
我喜欢这么多的Macports安装如何为你提供有关下一步操作的反馈。在服务器安装结束时,它显示以下内容:
******************************************************
* In order to setup the database, you might want to run
* sudo -u _mysql mysql_install_db5
* if this is a new install
******************************************************
对我来说,这是一个新安装(没有任何本地模式)。为了完整起见,以供我参考,以下是运行该命令的输出:
Installing MySQL system tables...
OK
Filling help tables...
OK
To start mysqld at boot time you have to copy
support-files/mysql.server to the right place for your system
PLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER !
To do so, start the server, then issue the following commands:
/opt/local/lib/mysql5/bin/mysqladmin -u root password 'new-password'
/opt/local/lib/mysql5/bin/mysqladmin -u root -h iMac.local password 'new-password'
Alternatively you can run:
/opt/local/lib/mysql5/bin/mysql_secure_installation
which will also give you the option of removing the test
databases and anonymous user created by default. This is
strongly recommended for production servers.
See the manual for more instructions.
You can start the MySQL daemon with:
cd /opt/local ; /opt/local/lib/mysql5/bin/mysqld_safe &
You can test the MySQL daemon with mysql-test-run.pl
cd /opt/local/mysql-test ; perl mysql-test-run.pl
Please report any problems with the /opt/local/lib/mysql5/bin/mysqlbug script!
The latest information about MySQL is available at http://www.mysql.com/
Support MySQL by buying support/licenses from http://shop.mysql.com/
快完成了 在“端口搜索”的早期,我遇到了一个有趣的端口:
py26-mysql @ 1.2.2(python,devel,数据库)mysql的Python接口
非常希望这会为我提供MySQLdb软件包,我安装了它(确实做到了)。
sudo port install py26-mysql
余言之后,我加速了python解释器的尝试,以导入MySQLdb,这一直都是我的方式。
iMac:~ drhoden$ python
Python 2.6.4 (r264:75706, Dec 15 2009, 18:00:14)
[GCC 4.2.1 (Apple Inc. build 5646) (dot 1)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import MySQLdb
/opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/MySQLdb/__init__.py:34: DeprecationWarning: the sets module is deprecated from sets import ImmutableSet
>>>
警告,但是有效!!
还有一件事:
sudo port install py26-django
完成所有这些工作之后,我终于能够启动Django项目并远程连接到公司的MySQL服务器!也许没有必要使用MacPorts重新安装Django,但是我并不会冒任何麻烦。
Django 的文件上传 在学习完 Django 的 Form 模块后,我们就用最后一个常用的文件上传的场景来结束本部分的内容。 1. Django 的文件上传实验 同样,话不多说,我们先通过两个上传的例子来看看 Django 的上传功能。 实验1:简单文件上传 准备本地文件,upload.txt,上传到服务器的 /root/test/django 目录下; 准备模板文件,显示上传按钮: <for
主要内容:上传图片对于Web应用程序,以便能够上传文件(资料图片,歌曲,PDF格式,文字......),它通常是很有用的。让我们在这一节中来讨论如何使用Django上传文件。 上传图片 在开始开发图片上传之前,请确保Python的图像库(PIL)已经安装。现在来说明上传图片,让我们创建一个配置文件格式,在 myapp/forms.py - 正如你所看到的,这里的主要区别仅仅是 forms.ImageField。Im
假设我有一个与产品模型具有多对一关系的图像模型,如下所示: 当尝试访问模板中图像标记上的{{product.get_primary_image.url}时,它会输出一个索引器而不是图像,即使在向数据库添加了多个图像之后,我仍然会得到索引错误。我哪里会出错?请帮帮我,我还是个新手。
问题内容: 我是django初学者,所以我试图理解上下文和上下文处理器的概念。 什么是上下文,为什么要使用它? 你是否需要上下文才能在模板中使用它? 上下文和上下文处理器是否相同? 非常感谢你的回复。提前致谢! 问题答案: 当你使用Django模板时,它会被编译一次(并且只能编译一次)并存储以供将来使用,作为优化。模板可以在双花括号中包含变量名,例如 和。 一个背景是变量名称为字典键和它们的值的值
问题内容: 我想在Mac OS X上的docker中运行Django应用。我已使用该教程安装了docker 。 我参考docker -library中的Django文档来构建映像https://github.com/docker- library/docs/tree/master/django ,我将Dockerfile添加到新的Django项目文件夹中 问题是我构建了映像并成功运行了容器,但是每
问题内容: 因此,我尝试上传没有任何外部插件的文件,但是遇到了一些错误。 我的服务器: 我收到请求的文件。 现在如何正确获取带有我的代码的上传文件? 问题答案: 我遵循了本教程http://www.script-tutorials.com/pure-html5-file- upload/ ,在php部分中,我替换为: 也改变了这行