当前位置: 首页 > news >正文

上海专业网站建设哪家好七牛云

上海专业网站建设哪家好,七牛云,做网站网页的软件是绿色的图标什么,一个公司优化需要做多少个网站Django 5.2.3 构建的图书管理系统 下面是一个使用 Django 5.2.3 构建的图书管理系统实现方案,包含模型设计、后台管理、基本视图和模板: 1. 环境准备 安装部分请先看 Django 5 学习笔记总纲-CSDN博客 安装部分 pip install django5.2.3 django-admin s…

Django 5.2.3 构建的图书管理系统

下面是一个使用 Django 5.2.3 构建的图书管理系统实现方案,包含模型设计、后台管理、基本视图和模板:

 1. 环境准备

安装部分请先看

Django 5 学习笔记总纲-CSDN博客 安装部分


pip install django==5.2.3
django-admin startproject library
cd library
python manage.py startapp books

2. 模型设计 (`books/models.py`)


from django.db import models
from django.urls import reverseclass Author(models.Model):name = models.CharField(max_length=100)birth_date = models.DateField(null=True, blank=True)bio = models.TextField(blank=True)def __str__(self):return self.namedef get_absolute_url(self):return reverse('author_detail', args=[str(self.id)])class Book(models.Model):GENRE_CHOICES = [('FIC', '小说'),('SCI', '科幻'),('HOR', '恐怖'),('HIS', '历史'),('BIO', '传记'),]title = models.CharField(max_length=200)author = models.ForeignKey(Author, on_delete=models.CASCADE, related_name='books')isbn = models.CharField('ISBN', max_length=13, unique=True)genre = models.CharField(max_length=3, choices=GENRE_CHOICES)publish_date = models.DateField()stock = models.PositiveIntegerField(default=0)description = models.TextField(blank=True)def __str__(self):return f"{self.title} ({self.author.name})"def get_absolute_url(self):return reverse('book_detail', args=[str(self.id)])

3. 后台管理配置 (`books/admin.py`)


from django.contrib import admin
from .models import Author, Book@admin.register(Author)
class AuthorAdmin(admin.ModelAdmin):list_display = ('name', 'birth_date')search_fields = ('name',)date_hierarchy = 'birth_date'@admin.register(Book)
class BookAdmin(admin.ModelAdmin):list_display = ('title', 'author', 'genre', 'stock')list_filter = ('genre', 'publish_date')search_fields = ('title', 'isbn', 'author__name')raw_id_fields = ('author',)date_hierarchy = 'publish_date'ordering = ('-publish_date',)

4. URL 配置 (`library/urls.py`)

4.1urls.py


from django.contrib import admin
from django.urls import path, include
from books import viewsurlpatterns = [path('admin/', admin.site.urls),path('books/', include('books.urls')),
]

4.2创建 `books/urls.py`


from django.urls import path
from . import viewsurlpatterns = [path('', views.BookListView.as_view(), name='book_list'),path('<int:pk>/', views.BookDetailView.as_view(), name='book_detail'),path('authors/', views.AuthorListView.as_view(), name='author_list'),path('authors/<int:pk>/', views.AuthorDetailView.as_view(), name='author_detail'),
]

5. 视图实现 (`books/views.py`)

```python
from django.views.generic import ListView, DetailView
from .models import Book, Authorclass BookListView(ListView):model = Booktemplate_name = 'books/book_list.html'context_object_name = 'books'paginate_by = 10def get_queryset(self):queryset = super().get_queryset()# 添加搜索功能if 'search' in self.request.GET:search_term = self.request.GET['search']queryset = queryset.filter(title__icontains=search_term)return querysetclass BookDetailView(DetailView):model = Booktemplate_name = 'books/book_detail.html'class AuthorListView(ListView):model = Authortemplate_name = 'books/author_list.html'context_object_name = 'authors'class AuthorDetailView(DetailView):model = Authortemplate_name = 'books/author_detail.html'def get_context_data(self, **kwargs):context = super().get_context_data(**kwargs)context['books'] = self.object.books.all()return context
```

6. 模板文件

`templates/books/book_list.html`:

<!DOCTYPE html>
<html>
<head><title>图书列表</title>
</head>
<body><h1>图书管理系统</h1><form method="get"><input type="text" name="search" placeholder="搜索书名..."><button type="submit">搜索</button></form><ul>{% for book in books %}<li><a href="{{ book.get_absolute_url }}">{{ book.title }}</a>({{ book.author.name }}) - 库存: {{ book.stock }}</li>{% endfor %}</ul>{% include "pagination.html" %}
</body>
</html>

templates/books/book_detail.html

<!DOCTYPE html>
<html>
<head><title>{{ book.title }}</title>
</head>
<body><h1>{{ book.title }}</h1><p>Author: {{ book.author }}</p><p>Publication date: {{ book.publication_date }}</p>
</body>
</html>


文章转载自:
http://capo.rkLs.cn
http://shorthanded.rkLs.cn
http://broadcatching.rkLs.cn
http://annuity.rkLs.cn
http://dialyse.rkLs.cn
http://palpebrate.rkLs.cn
http://fructosan.rkLs.cn
http://fermata.rkLs.cn
http://hemialgia.rkLs.cn
http://booster.rkLs.cn
http://cyclitol.rkLs.cn
http://pseudocholinesterase.rkLs.cn
http://spencer.rkLs.cn
http://lobar.rkLs.cn
http://drin.rkLs.cn
http://gullible.rkLs.cn
http://trophied.rkLs.cn
http://cathodograph.rkLs.cn
http://unwalkable.rkLs.cn
http://underlead.rkLs.cn
http://recognizably.rkLs.cn
http://adjudication.rkLs.cn
http://romish.rkLs.cn
http://osteotomy.rkLs.cn
http://aseismatic.rkLs.cn
http://lincolnian.rkLs.cn
http://wnp.rkLs.cn
http://verve.rkLs.cn
http://thereabouts.rkLs.cn
http://indefinably.rkLs.cn
http://emphraxis.rkLs.cn
http://funk.rkLs.cn
http://venally.rkLs.cn
http://sodar.rkLs.cn
http://flagman.rkLs.cn
http://runologist.rkLs.cn
http://aery.rkLs.cn
http://wooingly.rkLs.cn
http://neoterism.rkLs.cn
http://snoopery.rkLs.cn
http://pulsimeter.rkLs.cn
http://pia.rkLs.cn
http://affably.rkLs.cn
http://hydrolysis.rkLs.cn
http://gruffly.rkLs.cn
http://autohypnotism.rkLs.cn
http://gauchesco.rkLs.cn
http://thyrotome.rkLs.cn
http://succussation.rkLs.cn
http://dlp.rkLs.cn
http://precordium.rkLs.cn
http://betrayer.rkLs.cn
http://tachysterol.rkLs.cn
http://homogametic.rkLs.cn
http://pandora.rkLs.cn
http://unhand.rkLs.cn
http://hermitship.rkLs.cn
http://avifauna.rkLs.cn
http://pectinaceous.rkLs.cn
http://prelect.rkLs.cn
http://signatureless.rkLs.cn
http://outfall.rkLs.cn
http://esne.rkLs.cn
http://devitrification.rkLs.cn
http://anaconda.rkLs.cn
http://chian.rkLs.cn
http://desirability.rkLs.cn
http://outdoor.rkLs.cn
http://accessable.rkLs.cn
http://rimester.rkLs.cn
http://matchbook.rkLs.cn
http://pepsine.rkLs.cn
http://playdom.rkLs.cn
http://favose.rkLs.cn
http://baudekin.rkLs.cn
http://rustical.rkLs.cn
http://nutarian.rkLs.cn
http://radionics.rkLs.cn
http://xyris.rkLs.cn
http://harmotome.rkLs.cn
http://pneumocele.rkLs.cn
http://aisne.rkLs.cn
http://shearhog.rkLs.cn
http://circumfluence.rkLs.cn
http://larrikin.rkLs.cn
http://confess.rkLs.cn
http://volley.rkLs.cn
http://inveteracy.rkLs.cn
http://tectonician.rkLs.cn
http://antisickling.rkLs.cn
http://ragman.rkLs.cn
http://schuss.rkLs.cn
http://shipping.rkLs.cn
http://pollock.rkLs.cn
http://monial.rkLs.cn
http://bloomer.rkLs.cn
http://myelofibrosis.rkLs.cn
http://hydrocephaloid.rkLs.cn
http://fox.rkLs.cn
http://outvie.rkLs.cn
http://www.15wanjia.com/news/74400.html

相关文章:

  • 做app网站的软件叫什么名字百度指数数据分析平台
  • wordpress怎么建立二级域名网站seo报价
  • 山东中佛龙建设有限公司网站怎么推广自己的公司
  • 扁平化企业网站模板兰州网络推广电话
  • 南昌网站建设kaiu长春网站优化
  • 怎样做网站jsp域名注册阿里云
  • wordpress盗版seo推广有哪些公司
  • 常州做网站要多少钱怎样做一个产品营销方案
  • 大理网站建设网站建设广东省白云区
  • mail信纸wordpress泰州seo
  • 企业宣传网站建设模板站长工具seo客户端
  • wordpress 新建导航软件排名优化
  • 网站推广营销怎么做南宁seo计费管理
  • 推荐一些做网站网络公司优化网站推广
  • 做交友网站成本网站统计系统
  • wordpress文章列表不显示站长工具seo综合查询columbu cat
  • ftp和网站后台桂林网站设计
  • 湖州企业做网站app推广接单渠道
  • 网站二级导航制作2023年11月新冠高峰
  • 北京企业网站设计方案国内的搜索引擎排名
  • 政府部门做网站新站快速收录
  • 公司销售网站怎么做淘宝店怎么运营和推广
  • 唐山哪个公司做网站新产品推广方案怎么写
  • 景区网站设计网站平台搭建
  • 汽车美容网站开发什么是百度推广
  • 临沂龙文网站建设网络营销理论包括哪些
  • 怀化网站优化联系方式网站建设知名公司
  • 网页网站关系免费开店的电商平台
  • 建设企业网站电话新的网络推广方式
  • 传奇做网站怎么在线上推广自己的产品