在Python的Django框架中simple-todo工具的简单使用

yipeiwu_com6年前Python基础

缘起

simple-todo最早是web.py一个中文教程的例子。后来Uliweb的作者limodou 认为这个教程很不错,于是有了Uliweb版的simple-todo。接着又有了Bottle版和Flask版。这俨然成了一个FrameworksShow项目。既然是FrameworksShow, 那Django的总不应当缺了吧。

simple-todo: 一个简易的 todo 程序
http://simple-is-better.com/news/309

Simple Todo (Uliweb 版本) 教程 by @limodou
http://simple-is-better.com/news/312

Simple-TODO Bottle 实现版 by @zoomquiet
http://simple-is-better.com/news/509

Simple-TODO Flask实现版 by @wyattwang
http://simple-is-better.com/news/524
运行需求

Django>=1.3
安装及运行

初始化数据库: python manage.py syncdb

启动: python manage.py runserver

使用: 在浏览器中打开 http://127.0.0.1:8000/

Django Admin: 在浏览器中打开 http://127.0.0.1:8000/admin/
项目开发记录

    创建django project和app:
 
  

 django-admin.py startproject simple_todo_site
  cd simple_todo_site/
  python manage.py startapp simpletodo

    编辑settings.py完成数据库、模板、静态文件等配置,主要配置条目:

    #注:我认为django应当加更多的默认设置,这些配置改的挺烦
    DATABASES
    INSTALLED_APPS
    STATIC_ROOT
    STATICFILES_DIRS
    TEMPLATE_DIRS
    编辑urls.py把django admin和static文件url配置加上。
    编辑simpletodo/models.py,完成数据模型:

     
   

 from django.db import models
  from django.contrib import admin
   
  class Todo(models.Model):
    title = models.CharField( max_length=255)
    finished = models.IntegerField(default=0)
   
    def __unicode__(self):
      return self.title

    创建数据库:
 

  python manage.py syncdb

    跑起来,进django admin看看先:
  

 python manage.py runserver
  #http://127.0.0.1:8000/admin/

相关文章

Python3.5内置模块之shelve模块、xml模块、configparser模块、hashlib、hmac模块用法分析

Python3.5内置模块之shelve模块、xml模块、configparser模块、hashlib、hmac模块用法分析

本文实例讲述了Python3.5内置模块之shelve模块、xml模块、configparser模块、hashlib、hmac模块用法。分享给大家供大家参考,具体如下: 1、shelve...

Pycharm导入Python包,模块的图文教程

Pycharm导入Python包,模块的图文教程

1、点击File->settings 2、选择Project Interpreter,点击右边绿色的加号添加包 3、输入你想添加的包名,点击Install Package 4...

简单了解python模块概念

本文主要讲述的是Python中的模块的概念,具体如下。 模块是python组织代码的基本方式: python的脚本都是用扩展名为py的文本文件保存的。 一个脚本可以单独运行,也可以导入...

Python多继承原理与用法示例

Python多继承原理与用法示例

本文实例讲述了Python多继承原理与用法。分享给大家供大家参考,具体如下: python中使用多继承,会涉及到查找顺序(MRO)、重复调用(钻石继承,也叫菱形继承问题)等 MRO MR...

Python中有趣在__call__函数

Python中有一个有趣的语法,只要定义类型的时候,实现__call__函数,这个类型就成为可调用的。 换句话说,我们可以把这个类型的对象当作函数来使用,相当于 重载了括号运算符。...