日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁(yè) > 运维知识 > windows >内容正文

windows

使用django创建一个单表查询的图书管理系统

發(fā)布時(shí)間:2023/12/20 windows 28 豆豆
生活随笔 收集整理的這篇文章主要介紹了 使用django创建一个单表查询的图书管理系统 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

使用django創(chuàng)建一個(gè)單表查詢的圖書管理系統(tǒng)

在settings.py文件中添加(用于連接mysql數(shù)據(jù)庫(kù))

DATABASES = {'default': {'ENGINE': 'django.db.backends.mysql','NAME': 'djangotest','HOST': '127.0.0.1','PORT': 3306,'USER': 'root','PASSWORD': '123'} }

在init.py文件中添加(替換默認(rèn)的MySQLdb)

import pymysql pymysql.install_as_MySQLdb()

在models.py文件中添加創(chuàng)建表和字段的語句

from django.db import models# Create your models here. class Books(models.Model):id = models.AutoField(primary_key=True)name = models.CharField(max_length=255)price = models.FloatField()author = models.CharField(max_length=255)publish = models.CharField(max_length=255)

在終端中執(zhí)行創(chuàng)建的命令

python3 manage.py makemigrations python3 manage.py migrate

配置路由urls.py

from django.conf.urls import url from django.contrib import admin from books import viewsurlpatterns = [url(r'^admin/', admin.site.urls),url(r'^index/', views.login),url(r'^$', views.login), ]

寫視圖函數(shù)views.py

from books import models# Create your views here. def login(request):msg = models.Books.objects.all()return render(request, 'index.html',{'res_list':msg})

寫前端頁(yè)面index.html

<!DOCTYPE html> <html lang="zh"> <head><meta charset="UTF-8"><title>主頁(yè)</title><style>body, html, ul, li {margin: 0;padding: 0;}ul {list-style: none;}.header_t {text-align: center;margin: 10px auto;line-height: 80px;}.header {width: 100%;height: 80px;background-color: azure;}.fd_title {background-color: aqua;line-height: 60px;text-align: center;}.fd_bd {width: 100%;height: 400px;background-color: chocolate;}.fd_form {margin-left: 90px;}.fd_form input {height: 40px;width: 800px;font-size: 20px;}.fd_form button {height: 40px;width: 80px;}.fdf_res {width: 900px;font-size: 18px;}li {float: left;height: 28px;width: 178px;background-color: aqua;border: 1px solid black;text-align: center;line-height: 29px;}.fdf_res li{background-color: snow;}</style> </head> <body> <div class="header"><div class="header_t"><h1>圖書管理系統(tǒng)</h1></div><div class="find_book"><div class="fd_title"><h2>查詢書籍</h2></div><div class="fd_bd"><div class="fd_form"><form action="index.html" method="post"><input type="text" name="bookn" placeholder="請(qǐng)輸入書名" AUTOCOMPLETE="off"><button type="submit">提交</button></form><h3>查詢結(jié)果:</h3><ul><li>編號(hào)</li><li>書名</li><li>價(jià)格</li><li>作者</li><li>版本</li></ul><div class="fdf_res">{% for i in res_list%}<ul><li>{{ i.id }}</li><li>{{ i.name }}</li><li>{{ i.price }}</li><li>{{ i.author }}</li><li>{{ i.publish }}</li></ul>{% endfor %}</div></div></div></div> </div></body> </html>

轉(zhuǎn)載于:https://www.cnblogs.com/jianhaozhou/p/9910816.html

總結(jié)

以上是生活随笔為你收集整理的使用django创建一个单表查询的图书管理系统的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。