django项目 小示例 图书管理系统
2017-08-20 00:48
435 查看
编写models后进行表的初始化和生成
python manage.py makemigrations
python manage.py migrate
sqlite的驱动安装http://blog.csdn.net/qq_36482772/article/details/53458400
拷贝bootstrap到static
setting最后追加 STATIC_ROOT=os.path.join(BASE_DIR,'book/static/bootstrap-3.3.7-dist')
urls.py文件内容
views文件内容
modlels.py文件内容
页面内容
index
addbook
附加
setting追加
为了引入bootstrap
boot下拷贝入bootstrap的dist文件夹 js下拷贝入jQuery
并且注释47行 为了post请求 不被拦截
python manage.py makemigrations
python manage.py migrate
sqlite的驱动安装http://blog.csdn.net/qq_36482772/article/details/53458400
拷贝bootstrap到static
setting最后追加 STATIC_ROOT=os.path.join(BASE_DIR,'book/static/bootstrap-3.3.7-dist')
urls.py文件内容
from django.conf.urls import url from django.contrib import admin from book import views urlpatterns = [ url(r'^admin/', admin.site.urls), url(r'^index/', views.index), url(r'^addBook/', views.addBook), url(r'^delete/', views.delete), url(r'^addBook/', views.addBook), url(r'^edit/', views.edit), ]
views文件内容
from django.shortcuts import render, redirect # from book import models from book.models import * # Create your views here. def index(request): all_book_list = Book.objects.all() # 取到的内容为[obj1,obj2,obj3] return render(request, "index.html", {"all_book_list":all_book_list}) def addBook(request): if request.method == 'POST': title = request.POST.get('title') price = request.POST.get('price') author = request.POST.get('author') publish = request.POST.get('publish') print(request.POST) # 数据库添加操作 Book.objects.create(title=title, price=price, author=author, publish=publish) return redirect("/index/") return render(request, "addBook.html") def delete(request,): id=request.GET.get("id") Book.objects.filter(id=id).delete() return redirect("/index/") def edit(request): Book.objects.filter(id=id).update(title="title") # Book.objects.filter() return redirect("/index/")
modlels.py文件内容
from django.db import models # Create your models here. class Book(models.Model): #id = models.IntegerField() title = models.CharField(max_length=32) # 字符串 price=models.IntegerField() author=models.CharField(max_length=32) publish=models.CharField(max_length=32)
页面内容
index
{% load staticfiles %} {##新增内容#} <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Title</title> <style> .outer { margin: 100px auto; height: 400px; {# background-color: greenyellow;#} border: 0px solid rebeccapurple; width: 75%; } </style> {# //引入外部文件#} <link rel="stylesheet" href="{% static "dist/css/bootstrap.css" %}"> <script src="{% static "dist/js/jquery-3.1.1.js" %}"></script> <script src="{% static "dist/js/bootstrap.js" %}"></script> </head> <body> <div class="outer"> <a href="/addBook/"> <button type="button" class="btn btn-primary">添加</button> <br/></a> <hr/> <table class="table table-striped"> <tr> <th>编号</th> <th>名字</th> <th>价格</th> <th>作者</th> <th>出版社</th> <th>管理</th> </tr> {% for book in all_book_list %} <tr> <td>{{ book.id }}</td> <td>{{ book.title }}</td> <td>{{ book.price }}</td> <td>{{ book.author }}</td> <td>{{ book.publish }}</td> <td><a href="/delete/?id={{ book.id }}"> <button type="button" class="btn btn-danger">删除</button> </a> <a href="/edit/?id={{ book.id }}"> <button type="button" class="btn btn-info">修改</button> </a></td> </tr> {% endfor %} {# {{ all_book_list }}#} </table> </div> </body> </html>
addbook
{% load staticfiles %} <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Title</title> <link rel="stylesheet" href="{% static "dist/css/bootstrap.css" %}"> <script src="{% static "dist/js/jquery-3.1.1.js" %}"></script> <script src="{% static "dist/js/bootstrap.js" %}"></script> </head> <style> .addbook{ margin-top: 10%; margin-right: 50%; } </style> <body> <br> <div class="addbook"> <form class="form-horizontal" action="" method="post"> <div class="form-group"> <label for="title" class="col-sm-2 control-label">名字</label> <div class="col-sm-10"> <input type="text" class="form-control" id="title" placeholder="title" name="title"> </div> </div> <div class="form-group"> <label for="price" class="col-sm-2 control-label">价格</label> <div class="col-sm-10"> <input type="text" class="form-control" id="price" placeholder="price" name="price"> </div> </div> <div class="form-group"> <label for="author" class="col-sm-2 control-label">作者</label> <div class="col-sm-10"> <input type="text" class="form-control" id="author" placeholder="author" name="author"> </div> </div> <div class="form-group"> <label for="publish" class="col-sm-2 control-label">出版社</label> <div class="col-sm-10"> <input type="text" class="form-control" id="publish" placeholder="publish" name="publish"> </div> </div> {# <div class="form-group">#} {# <div class="col-sm-offset-2 col-sm-10">#} {# <div class="checkbox">#} {# <label>#} {# <input type="checkbox"> Remember me#} {# </label>#} {# </div>#} {# </div>#} {# </div>#} <div class="form-group"> <div class="col-sm-offset-2 col-sm-10"> <button type="submit" class="btn btn-default">提交</button> </div> </div> </form> </div> </body> </html>
附加
setting追加
STATIC_ROOT=os.path.join(BASE_DIR,'book/static/dist')
为了引入bootstrap
boot下拷贝入bootstrap的dist文件夹 js下拷贝入jQuery
并且注释47行 为了post请求 不被拦截
相关文章推荐
- 小组图书管理系统项目进度表
- 关于Java小项目——图书管理系统的总结
- Struts1.x+Hibernate+FCKedit+Mysql在线天下新闻管理系统项目示例图
- JAVA项目(二)——图书管理系统
- ssh练习项目-----自助图书管理系统
- c/c++ 数据结构-线性表(线性表定义 企业工程项目:图书管理系统)
- 传智播客 网上图书管理系统之项目导入
- 图书管理系统项目总结(转贴)
- Django 一个简单的图书管理程序(一建立项目)
- 结对项目 —— 图书管理系统实验报告
- Asp.Net小项目的小项目-实现图书管理系统中对读者的一些操作
- 学习笔记☞面向对象编程示例(日记本管理系统项目)
- ☆首发☆非常适合学习理解laravel的项目--图书管理系统
- Java web项目 图书管理系统登录部分代码
- C语言项目2:图书管理系统
- java web 项目 图书管理系统的设计与实现
- C项目实践--图书管理系统(1)
- C语言项目2:图书管理系统
- java web 项目 图书管理系统的设计与实现
- Django创建图书管理项目(完整版