在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 Unittest根据不同测试环境跳过用例的方法

Python Unittest根据不同测试环境跳过用例的方法

前言 在利用单元测试框架执行测试用例的过程中,有时只需要执行一部分用例,或者跳过某些暂不需要执行的用例,python的unittest框架就内置这样的功能。 本文章会讲述以下几个内容:...

python实现读取命令行参数的方法

本文实例讲述了python读取命令行参数的方法。分享给大家供大家参考。具体分析如下: 如果想对python脚本传参数,python中对应的argc, argv(c语言的命令行参数)是什么...

python中实现定制类的特殊方法总结

看到类似__slots__这种形如__xxx__的变量或者函数名就要注意,这些在Python中是有特殊用途的。 __slots__我们已经知道怎么用了,__len__()方法我们也知道是...

python读取TXT每行,并存到LIST中的方法

python读取TXT每行,并存到LIST中的方法

文本如图: Python: import sys result=[] with open('accounts.txt','r') as f: for line in f: re...

python中实现字符串翻转的方法

具体代码如下所示: #字符串反转 def reverse (s): rt = '' for i in range(len(s)-1,-1,-1): rt += s[i...