cstar

eli's docs

   :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

2013年10月18日

摘要: 本节介绍 Form 中一些字段类型的使用,以文件上传字段 FileField 为例:(注,其它字段和相关用法见官方文档中的 Forms -> Built-in Fields)一,配置 urls.py:from django.conf.urls import patterns, include, url# Uncomment the next two lines to enable the admin:from django.contrib import adminadmin.autodiscover()urlpatterns = patterns('', # Exampl 阅读全文
posted @ 2013-10-18 22:33 exclm 阅读(896) 评论(0) 推荐(0) 编辑

2013年10月16日

摘要: 本讲开始介绍 Django 中表单的应用。依然以前面的工程为例继续演示。一,创建 url 映射,编辑 csvt03/urls.py:from django.conf.urls import patterns, include, url# Uncomment the next two lines to enable the admin:from django.contrib import adminadmin.autodiscover()urlpatterns = patterns('', # Examples: # url(r'^$', 'csvt03. 阅读全文
posted @ 2013-10-16 22:08 exclm 阅读(299) 评论(0) 推荐(0) 编辑

2013年10月13日

摘要: 本讲介绍数据在页面中的呈现,内容很简单,就是嵌套循环在模板中的使用。一,修改 csvt03/urls.py:from django.conf.urls import patterns, include, url# Uncomment the next two lines to enable the admin:from django.contrib import adminadmin.autodiscover()urlpatterns = patterns('', # Examples: # url(r'^$', 'csvt03.views.home&# 阅读全文
posted @ 2013-10-13 20:09 exclm 阅读(366) 评论(0) 推荐(0) 编辑

2013年10月12日

摘要: 本讲介绍数据库多对多关系,代码样例继前文使用。一,在 blog/models.py 中创建对象:# Many-To-Many Example : Authors vs Booksclass Author(models.Model): name = models.CharField(max_length=20) def __unicode__(self): return self.nameclass Book(models.Model): name = models.CharField(max_length=20) authors = models.Many... 阅读全文
posted @ 2013-10-12 23:00 exclm 阅读(958) 评论(0) 推荐(0) 编辑

2013年10月11日

摘要: 本讲演示简单使用 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', # 阅读全文
posted @ 2013-10-11 22:46 exclm 阅读(293) 评论(0) 推荐(0) 编辑

2013年10月9日

摘要: models 模块中的对象有三种对应关系:多对一,多对多,一对一。本讲说明多对一关系。blog/models.py:from django.db import modelsclass Employee(models.Model): name = models.CharField(max_length=20) # map 'name' field to db def __unicode__(self): return self.nameclass Entry(models.Model): name = models.CharField(max_length=20... 阅读全文
posted @ 2013-10-09 22:53 exclm 阅读(699) 评论(0) 推荐(0) 编辑

2013年10月8日

摘要: 继django: db howto - 1 :一 操作数据库的三种方式:[root@bogon csvt03]# python2.7 manage.py shellPython 2.7.5 (default, Sep 20 2013, 07:02:05)>>> from blog.models import Employee>>> emp = Employee()>>> emp.name="One">>> emp.save()>>> emp = Employee(name=" 阅读全文
posted @ 2013-10-08 21:57 exclm 阅读(269) 评论(0) 推荐(0) 编辑

2013年10月5日

摘要: 以在 Django 中使用 MySQL 为例,首先要安装 MySQL 和 MySQL-python 组件,确保 python 能执行 import MySQLdb。MySQL 中创建数据库:[root@bogon csvt03]# mysql -uroot -pEnter password:mysql> create database csvt default charset utf8;Query OK, 1 row affected (0.01 sec)mysql>创建工程 csvt03,并修改 csvt03/settings.py 中的数据库设置:DATABASES = { & 阅读全文
posted @ 2013-10-05 22:48 exclm 阅读(557) 评论(0) 推荐(0) 编辑

2013年10月3日

摘要: 模板的作用方法有如下三种:blog/views.py:from django.template import loader, Context, Templatefrom django.http import HttpResponsefrom django.shortcuts import render_to_response as r2rdef index(req): t = loader.get_template('index.html') c = Context({'uname':'eli'}) html = t.render(c) retu 阅读全文
posted @ 2013-10-03 22:27 exclm 阅读(991) 评论(0) 推荐(0) 编辑

2013年10月2日

摘要: django 的 url 配置主要在 urls.py 中进行urlconfig 中对 url 的处理方式主要在:一 视图处理方式如 上文 例子所示:url(r'^blog/index/$', 'blog.views.index'),二 直接用方法名代表 url 处理方式:from django.conf.urls import patterns, include, urlfrom hi.views import index# Uncomment the next two lines to enable the admin:# from django.contri 阅读全文
posted @ 2013-10-02 21:51 exclm 阅读(683) 评论(0) 推荐(0) 编辑

2013年10月1日

摘要: 本节介绍模板中的内置标签:if for承上文,修改 views.py 如下:from django.shortcuts import render_to_responseclass Person(object): def __init__(self, name, age, sex): ... 阅读全文
posted @ 2013-10-01 15:40 exclm 阅读(403) 评论(0) 推荐(0) 编辑

2013年9月29日

摘要: 模板变量用双大括号显示,如:page title: {{title}}一 模板中使用变量继续前面的例子,修改 index.html: {{title}} {{context}} 修改 views... 阅读全文
posted @ 2013-09-29 23:25 exclm 阅读(925) 评论(0) 推荐(0) 编辑

2013年9月27日

摘要: 本文接 django: startproject。方法一:1 创建模板文件在 project_name/blog 下创建模板目录 templates:# cd project_name/blog# mkdir templatestemplates 目录中创建模板文件 index.html: Django Template Django Template Learning. View Code 2 在视图中发布模板修改 blog/views.py:from django.http impor... 阅读全文
posted @ 2013-09-27 22:28 exclm 阅读(394) 评论(0) 推荐(0) 编辑

2013年9月26日

摘要: python 的 django 框架的安装教程很多,这里不列举安装过程,直接开始记开发应用过程。1 startprojec,新建项目$ django-admin.py startproject project_name生成一个与 project_name 同名的项目目录,项目目录文件如下:$ ls ... 阅读全文
posted @ 2013-09-26 21:41 exclm 阅读(3889) 评论(2) 推荐(0) 编辑

2013年1月22日

摘要: Windows:Windows Registry Editor Version 5.00[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Keyboard Layout]"Scancode Map"=hex:00,00,00,00,00,00,00,00,03,00,00,00,3a,00,01,00,01,00,3a,00,00,00,00,00Linux:对于ubuntu有直接的可以设置;对于有些不能直接设置的linux发行版:$ cat > locktoescremove Lock = Caps_Lockk 阅读全文
posted @ 2013-01-22 13:40 exclm 阅读(608) 评论(0) 推荐(0) 编辑