Django1.8+Python3.4+Mysql5.5
2015-06-17 19:30
956 查看
1、开发环境
系统:数据库:
编程语言:
框架:
IDE:
PyCharm 4.5
2、新建Django工程,配置
新建Django工程:?
官网介绍:
The outer Django_Test/ root
directory is just a container for your project. Its name doesn’t matter to Django; you can rename it to anything you like.
manage.py: A command-line utility that lets you interact with this Django project in various ways. You can read all the details about manage.py in django-admin
and manage.py.
The inner Django_Test/ directory
is the actual Python package for your project. Its name is the Python package name you’ll need to use to import anything inside it .
Django_Test/__init__.py:
An empty file that tells Python that this directory should be considered a Python package. (Read more
about packages in the official Python docs if you’re a Python beginner.)
Django_Test/settings.py:
Settings/configuration for this Django project. Django settings will tell
you all about how settings work.
Django_Test/urls.py:
The URL declarations for this Django project; a “table of contents” of your Django-powered site. You can read more about URLs in URL
dispatcher.
Django_Test/wsgi.py:
An entry-point for WSGI-compatible web servers to serve your project. See How
to deploy with WSGI for more details.
启动工程:
?
说明你已经正确启动了Django工程!
配置Django对Mysql操作:
关于python3.4连接mysql请看这篇文章:/article/3479395.html
默认情况下,Django连接的是SqlLite,现在我们需要配置Mysql:
现在我们用PyMySQL: 官网地址:https://github.com/PyMySQL/PyMySQL/
?
1.在__init__.py文件中,添加这句话
?
?
3、自动生成数据库表
Django项目是按照模块来开发的,我们先建立一个.?
user/migrations: 数据库迁移用文件夹,创建的migrate会存在这个文件夹里。
user/_init_.py: 初始化数据信息。
user/admin.py:当前应用在Django管理界面的设置。
user/models.py:模型文件,用 Python 类来描述数据表。
user.tests.py:单元测试文件。
user.views.py:视图展示部分。
配置:
user/models.py(表结构从网上资源活取得到,实际使用根据具体情况):
?
?
检查配置文件
生成数据库表:
数据库表:
有了这些,我们就可以在此基础堆积代码了。
相关文章推荐
- Python正则表达式操作指南
- [python]Python中变量的作用域(variable scope)
- ArcGIS Python 批量定义投影
- Python 字符串操作
- Python - 装饰器使用过程中的误区
- Python - 装饰器使用过程中的误区
- [python]Python中:self和__init__的含义,以及为何要有self和__init__
- python爬虫 爬取知乎用户的用户信息
- python调用java
- python greenlet背景介绍与实现机制
- 八皇后问题python实现
- 用Python写单向链表和双向链表
- 呵呵!手把手带你在 IIS 上运行 Python(转)
- ArcGIS Python批量插值、裁切
- 一个小玩具:Python调用Mysql
- Python 列表(list)、字典(dict)、字符串(string)常用基本操作小结
- python字符串字串查找 find和index方法
- Python开发工具PyCharm个性化设置(图解)
- 回车(\r)和换行(\n)真蛋疼
- python各种类型转换-int,str,char,float,ord,hex,oct等