django新建项目,连接mysql数据库
2016-05-06 16:29
711 查看
安装django,进入Django目录,运行 python setup.py install
在workplace目录下新建一个名为site01的项目:
cd workplace
django-admin.py startproject site01 ,在workplace目录下自动生成site01目录及其里面的内容
在site01下新建一个名为app01的app:
python manage.py startapp app01
启动项目site01下的WEB服务:
cd site01
python manage.py runserver 0.0.0.0:80
注:
#####################################################
django配置连接mysql数据库
1.python需要先安装mysql模块,否则在django的settings.py中配置mysql连接后,在python manage.py runserver的时候会报错“django.core.exceptions.ImproperlyConfigured: Error loading MySQLdb module: No module named MySQLdb”
2.配置相应project下的settings.py,默认使用mysql,修改如下:
在运行python manage.py migrate同步数据库时,如果出现如下报错则说明连接mysql的用户没有足够的权限,dba添加相应权限即可
注:root'@'192.168.50.74 全部是用户名
安装MySQL-python步骤如下(Windows10):
1.运行python mysqlregistry.py,否则在安装MySQL-python时候会提示找不到python2.7
2.http://www.dlldll.com/ 下载libguide40.dll和 libmmd.dll这两个文件,然后拷贝到C:\WINDOWS/system32/ 目录下
3.http://www.codegood.com/downloads 下载MySQL-python-1.2.3.win-amd64-py2.7.exe
安装完成后在python下可以导入import MySQLdb
mysqlrgistry.py文件内容:
在workplace目录下新建一个名为site01的项目:
cd workplace
django-admin.py startproject site01 ,在workplace目录下自动生成site01目录及其里面的内容
在site01下新建一个名为app01的app:
python manage.py startapp app01
启动项目site01下的WEB服务:
cd site01
python manage.py runserver 0.0.0.0:80
注:
#####################################################
django配置连接mysql数据库
1.python需要先安装mysql模块,否则在django的settings.py中配置mysql连接后,在python manage.py runserver的时候会报错“django.core.exceptions.ImproperlyConfigured: Error loading MySQLdb module: No module named MySQLdb”
2.配置相应project下的settings.py,默认使用mysql,修改如下:
DATABASES = { 'default': { 'ENGINE': 'django.db.backends.mysql', 'NAME': 'testly', #db name 'USER': 'root', #db user 'PASSWORD': '123456789', 'HOST':'192.168.1.1', #db server 'PORT':'3306', #留空表示默认端口 } }
在运行python manage.py migrate同步数据库时,如果出现如下报错则说明连接mysql的用户没有足够的权限,dba添加相应权限即可
注:root'@'192.168.50.74 全部是用户名
安装MySQL-python步骤如下(Windows10):
1.运行python mysqlregistry.py,否则在安装MySQL-python时候会提示找不到python2.7
2.http://www.dlldll.com/ 下载libguide40.dll和 libmmd.dll这两个文件,然后拷贝到C:\WINDOWS/system32/ 目录下
3.http://www.codegood.com/downloads 下载MySQL-python-1.2.3.win-amd64-py2.7.exe
安装完成后在python下可以导入import MySQLdb
mysqlrgistry.py文件内容:
# # script to register Python 2.0 or later for use with win32all # and other extensions that require Python registry settings # # written by Joakim Loew for Secret Labs AB / PythonWare # # source: # http://www.pythonware.com/products/works/articles/regpy20.htm # # modified by Valentine Gogichashvili as described in http://www.mail-archive.com/distutils-sig@python.org/msg10512.html import sys from _winreg import * # tweak as necessary version = sys.version[:3] installpath = sys.prefix regpath = "SOFTWARE\\Python\\Pythoncore\\%s\\" % (version) installkey = "InstallPath" pythonkey = "PythonPath" pythonpath = "%s;%s\\Lib\\;%s\\DLLs\\" % ( installpath, installpath, installpath ) def RegisterPy(): try: reg = OpenKey(HKEY_CURRENT_USER, regpath) except EnvironmentError as e: try: reg = CreateKey(HKEY_CURRENT_USER, regpath) SetValue(reg, installkey, REG_SZ, installpath) SetValue(reg, pythonkey, REG_SZ, pythonpath) CloseKey(reg) except: print "*** Unable to register!" return print "--- Python", version, "is now registered!" return if (QueryValue(reg, installkey) == installpath and QueryValue(reg, pythonkey) == pythonpath): CloseKey(reg) print "=== Python", version, "is already registered!" return CloseKey(reg) print "*** Unable to register!" print "*** You probably have another Python installation!" if __name__ == "__main__": RegisterPy()
相关文章推荐
- 从库crash一直自动重启(mysqld got signal 11)问题解决
- [mysq]ERROR 2006 (HY000) at line xx: MySQL server has gone away 解决方法
- MySQL监控系统Lepus
- 使用DBOutputFormat把MapReduce产生的结果集导入到mysql中
- mysql性能监控指标
- zabbix监控mysql
- vsftpd+openssl+mysql实现sftp和ftp虚拟用户
- SQL Server 维护计划实现数据库备份(Step by Step)(转)
- 企业级-Mysql双主互备高可用负载均衡架构(基于GTID主从复制模式)
- lepus3.7 天兔监控安装手册 CentOS6.5+mysql5.6
- PL/SQL Developer使用技巧 快捷键
- Mysql limit分页语句用法 SqlServer TOP子句 Oracle分页
- MySQL_Database_Show_Create_Drop
- MySQL_Table_Create_Describe_Alter_Drop
- django1.10+mysql/connector 2.1.3运行polls demo的问题
- Django(一)基于mysql的网页
- golang 使用sql语句操作数据库的方法
- Top 20+ MySQL Best Practices
- SQL大圣之路笔记——SQL TRUNCATE,DELETE,DROP
- PLSQL Developer连接64位oracle