i am not familiar with DB opertions. usually i stroe data to txt and other formats. as DB is more and more popular, i want to try it too. i have some knowledge about Django. the DB opertions in Django is very easy than the DB source code. so i decide…
要用python链接到数据库,又不想写太多代码.想到了django,就偷懒了下.用django.db直连. django版本:1.6.5 (1.5以后可以用以下代码) #coding=utf-8 __author__ = 'tommy.yu' from django.db import connection from django.conf import settings """ settings.configure( ENGINE ='django.db.backends.…
汇总操作 注:polls为应用名 1.执行命令:python manage.py migrate,生成默认的数据库表等 2.修改应用的models.py文件,添加数据库表模型等 3.INSTALLED_APPS中添加应用 4.执行命令:python manage.py makemigrations polls ,查看sql语句:python manage.py sqlmigrate polls 0001 0001根据情况而定 5.执行命令:python manage.py migrate 一.数…
1 安装: pip  install django==1.11.9 另外:在pycharm中安装 django,在下图中七步走 2. 新建Django项目  django-admin startproject 项目名 3. Django 设置 settings.py文件中 1. 注释掉 csrf相关的那一行(大概是46行!) 2. 配置html文件相关 3. 配置静态文件相关 /static/ 4. 基础必备的三件套 1. HttpResponse --> 字符串 2. render() -->…
F() 的执行不经过 python解释器,不经过本机内存,是生成 SQL语句的执行. # Tintin filed a news story! reporter = Reporters.objects.get(name='Tintin') reporter.stories_filed += 1 reporter.save() # 等于 from django.db.models import F reporter = Reporters.objects.get(name='Tintin') re…
# coding=utf-8 from django.db import models """ Django数据库关系: 一对一关系:OneToOneField 多对多关系:ManyToManyField 多对一关系:ForeignKey """ ## One-to-one relationships class Place(models.Model): name = models.CharField(max_length=50) address…
本讲介绍数据在页面中的呈现,内容很简单,就是嵌套循环在模板中的使用. 一,修改 csvt03/urls.py: from django.conf.urls import patterns, include, url # Uncomment the next two lines to enable the admin: from django.contrib import admin admin.autodiscover() urlpatterns = patterns('', # Example…
本讲演示简单使用 Django Admin 功能. 一,修改 settings.py,添加 admin 应用: INSTALLED_APPS = ( 'django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.sites', 'django.contrib.messages', 'django.contrib.staticfiles', 'blog', # Unc…
models 模块中的对象有三种对应关系:多对一,多对多,一对一.本讲说明多对一关系. blog/models.py: from django.db import models class Employee(models.Model): name = models.CharField(max_length=20) # map 'name' field to db def __unicode__(self): return self.name class Entry(models.Model):…
继 django: db howto - 1 : 一 操作数据库的三种方式: [root@bogon csvt03]# python2.7 manage.py shell Python 2.7.5 (default, Sep 20 2013, 07:02:05) >>> from blog.models import Employee >>> emp = Employee() >>> emp.name="One" >>&…