在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/

相关文章

python采集微信公众号文章

python采集微信公众号文章

本文实例为大家分享了python采集微信公众号文章的具体代码,供大家参考,具体内容如下 在python一个子目录里存2个文件,分别是:采集公众号文章.py和config.py。 代码如下...

详解Python self 参数

1、概述 1.1 场景 我们在使用 Python 中的 方法 method 时,经常会看到 参数中带有 self,但是我们也没对这个参数进行赋值,那么这个参数到底是啥意思呢? 2、知识点...

Python多进程同步简单实现代码

本文讲述了Python多进程同步简单实现代码。分享给大家供大家参考,具体如下: #encoding=utf8 from multiprocessing import Process,...

Flask入门教程实例:搭建一个静态博客

Flask入门教程实例:搭建一个静态博客

现在流行的静态博客/网站生成工具有很多,比如 Jekyll, Pelican, Middleman, Hyde 等等,StaticGen 列出了目前最流行的一些静态网站生成工具。 我们的...

用Python制作检测Linux运行信息的工具的教程

在这篇文章里,我们将会探索如何使用Python语言作为一个工具来检测Linux系统各种运行信息。让我们一起来学习吧。 哪种Python? 当我提到Python时,我一般是指CPython...