- 博客(16)
- 资源 (10)
- 收藏
- 关注
原创 Django Admin管理工具
Django Admin管理工具Django提供了基于web的管理工具,是通过django.contrib实现。在settings.py配置中的INSTALLED_APPS可以看到,如:INSTALLED_APPS = [ 'django.contrib.admin', 'django.contrib.auth', 'django.contrib.contenttypes',
2017-10-30 20:27:34 1379
原创 Django表单
Django表单GET方法请求处理在testdjango项目中,创建一个search.py文件,文件内容:from django.http import HttpResponsefrom django.shortcuts import render_to_response# 表单def search_from(requset): return render_to_response('s
2017-10-30 20:26:41 577
原创 Django模型
Django模型Django对各种数据库提供了很好的支持。包括MySQL,SQLite,Orcale等。Django为这些数据库提供了统一的调用api。可以根据不同的业务,选择不同的数据库。下面使用Mysql数据库作为演示。如果没有安装MySQL的驱动包,可以使用pip安装pip install pymysql数据库的配置在项目的settings.py文件中找到DATABASES配置项,将其信息改为
2017-10-30 20:25:56 719
原创 Djando模板
Djando模板在上一章节中,我们使用django.http.HttpResponse()来输出”Hello World!”,实际上并没有遵守MVT模式。下面针对上面的程序做一个修改,使其符合MVT模式。在test_django工程目录,创建一个templates目录,这个目录用于存放模板。在templates目录创建一个hello.html文件整个目录结构如:hello.html文件代码:<!
2017-10-30 20:25:08 663
原创 Django环境搭建及项目配置
Django环境搭建及项目配置Django是一个开放源代码的web应用框架,由Python语言编写而成。采用MVT模式,模型M,视图V,模板T。模型M:即数据存取层,处理与数据相关的所有事务,例如:如何存取数据,如何验证数据的有效性等等视图V:即表现层,处理与表现相关的决定,如何在页面或其他文档中进行显示。模板T:业务逻辑层,存取模型及调取恰当模板的相关逻辑。1. Django的开发环境搭建安装如果
2017-10-30 20:23:36 1816 1
原创 MongoDB数据库的基本操作
MongoDB数据库的基本操作在操作MongoDB数据库时,首先需要打开MongoDB服务。如:开启MongoDB服务net start MongoDB # MongoDB 是在上一章的配置环境中通过 --serviceName "MongoDB"配置的。关闭MongoDB服务net stop MongoDB MongoDB数据库相关操作连接数据库当我们开始MongoDB服务后
2017-10-26 11:18:02 4026
原创 MongoDB数据库的简介、安装、概念解析及数据类型
MongoDB数据库的简介、安装、概念解析及数据类型简介MongoDB是一个基于分布式文件存储的开源数据库系统。是有C++语言编写。MongoDB旨在为WEB应用提供可拓展的高性能数据库存储解决方案。MongoDB将数据存储为一个文档(document),数据结构由键值对(key=value)组成。MongoDB文档类似json对象。如:{"name":"amy" , "age":18}{"id":
2017-10-26 11:16:31 482
原创 Python之xlsx文件从MySQL数据库导入导出
Python之excel文件从MySQL数据库导入导出excel文件导入MySQL数据库import pymysqlimport xlrdimport xlwtdef get_conn(): conn = pymysql.connect(host='localhost', port=3306, user='root', passwd='root', db='db_xlsx', char
2017-10-22 16:03:19 6461
原创 Python之csv文件从MySQL数据库导入导出
Python从MySQL数据库中导出csv文件处理csv文件导入MySQL数据库import pymysqlimport csvimport codecsdef get_conn(): conn = pymysql.connect(host='localhost', port=3306, user='root', passwd='root', db='test_csv', charse
2017-10-22 16:02:12 17950
原创 Python之xlsx文件与csv文件相互转换
Python之xlsx文件转csv文件在Python中,可以使用xlrd和csv模块来处理Excel文件和csv文件。xlsx文件转csv文件import xlrdimport csvdef xlsx_to_csv(): workbook = xlrd.open_workbook('1.xlsx') table = workbook.sheet_by_index(0) wi
2017-10-21 22:28:44 91233 12
原创 Python之dict(或对象)与json之间的互相转化
Python之dict(或对象)与json之间的互相转化在Python语言中,json数据与dict字典以及对象之间的转化,是必不可少的操作。在Python中自带json库。通过import json导入。在json模块有2个方法,loads():将json数据转化成dict数据dumps():将dict数据转化成json数据load():读取json文件数据,转成dict数据dump():
2017-10-21 22:27:27 194269 3
原创 Python之MySQL数据库增删改查操作
Python之MySQL数据库操作Python之连接数据库import pymysql# 获取连接对象conn,建立数据库的连接def get_conn(): conn = pymysql.connect(host='localhost',port=3306,user='root',passwd='root',db='test1') # db:表示数据库名称 return c
2017-10-21 22:22:44 24386 5
原创 使用type动态创建类
使用type动态创建类动态语言和静态语言最大的不同,就是函数和类的定义,不是编译时定义的,而是运行时动态创建的。下面看一个例子:# 定义一个Person类class Person(object): def __init__(self): pass def say(self): print('say hello')p = Person()p.say()
2017-10-20 15:10:24 1210
原创 动态给类和对象添加属性和方法
动态给类和对象添加属性和方法动态给类和对象添加属性定义一个Person类class Person(object): def __init__(self, name): self.name = name给对象添加属性# 创建2个Person,分别为p1,p2p1 = Person('amy')print(p1.name)p1.age = 10 # 给p1对
2017-10-20 15:09:30 9706 1
原创 装饰器
装饰器装饰模式有很多经典的使用场景,例如插入日志、性能测试、事务处理等等,有了装饰器,就可以提取大量函数中与本身功能无关的类似代码,从而达到代码重用的目的。装饰器引入下面就简单举个例子:一天,A程序员接到一个登入的需求,写了一个方法。def login(): print('登入')login() # 输出 登入突然,产品经理想加入一个登入事件。于是A程序员对方法进行了修改。d
2017-10-20 15:07:25 398
原创 深拷贝和浅拷贝
深拷贝和浅拷贝浅拷贝:对变量进行比较浅层次的拷贝,比如变量的赋值,其实2个变量都指向同一个内存地址。内存地址共享。深拷贝:对变量进行深层次的拷贝,拷贝了一份数据,2个变量之间的内存地址是不一样的,但是内容一样。内存地址不共享。举个例子:浅拷贝:a = [1,2,3]b = aprint(a) # [1,2,3]print(b) # [1,2,3]print(id(a)) # 18
2017-10-20 15:06:21 350 1
Gradle for Android
2016-11-15
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人