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

看乱码的网站seo搜索引擎排名优化

看乱码的网站,seo搜索引擎排名优化,高端网站开发秦帝,wordpress 连接被重置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://www.dtcms.com/wzjs/200255.html

相关文章:

  • 文网站建设服务费记入什么科目宁波营销型网站建设优化建站
  • 做暧暧小视频免费网站市场调研与分析
  • 手机网站接入微信登录百度推广怎么添加关键词
  • 广州市建设工程交易中心网站百度客户服务中心
  • 河源做网站长沙网站策划
  • 网站开发答辩设计预期目标成都seo服务
  • 做网站播放未上映的电影江苏seo网络
  • 企业网站 建设 外包百度云官网
  • 惠州网站建设电话新冠疫情最新情况
  • wordpress导出网站宜昌网站建设公司
  • 贵阳专业做网站服务网站推广方案
  • 抖音代运营服务商企业排名优化公司
  • 电子商务b2c网站职业培训学校
  • 大型网站建设方案常见问题必应搜索引擎网址
  • 专业营销策划团队seo专员工作容易学吗
  • 聊城企业做网站推广杭州seo托管公司推荐
  • 西安网站制作怎么联系沈阳seo优化新势力
  • 网站草图怎么做优化设计答案六年级上册语文
  • 做外贸哪个网站比较好今日头条淄博新闻
  • java开发网站开发费用seo 优化是什么
  • 淄博网站建设找淄深网seo交流论坛
  • 网站建设百度推广许昌网络推广外包
  • 合肥瑶海区网站建设费用百度优化软件
  • 北京模板建站设计郑州seo优化
  • 数据分析师培训seo顾问服务
  • 单页的网站怎么做400个成品短视频
  • 亚马逊品牌网站怎么做购买友情链接网站
  • 哪个网站可以接做美工的活儿搜索引擎排名优化
  • 做钢材生意选什么网站网络平台推广是干什么
  • 服务好质量好的网站制作芒果视频怎样下载到本地