[python]毕业设计基于pythonWeb开发Django框架的图书商城管理系统源码+数据库文件

使用步骤:

1.下载依赖

pip install -i https://pypi.tuna.tsinghua.edu.cn/simple django

2.启动项目

 python manage.py runserver     

3.启动网页

点击这个访问项目

项目不依赖数据库 基于内存数据模拟

启动代码:

#!/usr/bin/env python
"""Django's command-line utility for administrative tasks."""
import os
import sys
import logging


def main():
    # logging.log("http://127.0.0.1:8000/book/")
    """Run administrative tasks."""
    os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'bookSystem.settings')
    try:
        from django.core.management import execute_from_command_line
    except ImportError as exc:
        raise ImportError(
            "Couldn't import Django. Are you sure it's installed and "
            "available on your PYTHONPATH environment variable? Did you "
            "forget to activate a virtual environment?"
        ) from exc
    execute_from_command_line(sys.argv)


if __name__ == '__main__':
    main()

视图实现代码:

from django.shortcuts import render, redirect

books = []


def initBooks():
    return books


books = [
    {
        'id': "1",
        'name': "红楼梦",
        'type': "古典小说",
        'jiesao': '《红楼梦》是中国文学史上一部长篇小说,被誉为中国封建社会的百科全书。',
        'author': '曹雪芹',
        'count': 10
    },
    {
        'id': "2",
        'name': "西游记",
        'type': "古典小说",
        'jiesao': '《西游记》是一部中国古典小说,以寓言的形式描写了唐僧师徒四人历经九九八十一难的奇幻旅程。',
        'author': '吴承恩',
        'count': 8
    },
    {
        'id': "3",
        'name': "三国演义",
        'type': "古典小说",
        'jiesao': '《三国演义》是中国历史小说,以三国时代的政治斗争为背景,展现了各种英雄豪杰的形象。',
        'author': '罗贯中',
        'count': 7
    },
    {
        'id': "4",
        'name': "水浒传",
        'type': "古典小说",
        'jiesao': '《水浒传》是中国古典小说,讲述了108位英雄好汉的故事,以忠义为主题。',
        'author': '施耐庵',
        'count': 6
    },
    {
        'id': "5",
        'name': "红岩",
        'type': "小说",
        'jiesao': '《红岩》是一部以重庆保卫战为背景的抗战小说,表现了青年学生的爱国情感。',
        'author': '冯雪峰',
        'count': 5
    }
]


def index(request):
    return render(request, 'login.html')


def home(request):
    id = request.GET.get("id")
    name = request.GET.get("name", "")

    filtered_books = []

    if id or name:
        for book in initBooks():
            if (id and book["id"] == id) or (name and name in book["name"]):
                filtered_books.append(book)
    else:

        filtered_books = initBooks()

    return render(request, 'book/index.html', {'books': filtered_books})


def add(request):
    if request.method == 'GET':
        return render(request, 'book/add.html')
    else:
        id = request.POST.get('id', '')
        name = request.POST.get('name', '')
        type = request.POST.get('type', '')
        jiesao = request.POST.get('jiesao', '')
        author = request.POST.get('author', '')
        count = request.POST.get('count', '')

        new_book = {
            'id': id,
            'name': name,
            'type': type,
            'jiesao': jiesao,
            'author': author,
            'count': count
        }
        books.append(new_book)

        return redirect('/book/home')


def edit(request):
    if request.method == 'GET':
        id = request.GET.get("id")

        for book in books:
            if book['id'] == id:
                return render(request, 'book/edit.html', {'book': book})

    else:
        id = request.POST.get("id")
        name = request.POST.get('name', '')
        type = request.POST.get('type', '')
        jiesao = request.POST.get('jiesao', '')
        author = request.POST.get('author', '')
        count = request.POST.get('count', '')

        for book in books:
            if book['id'] == id:
                book['name'] = name
                book['type'] = type
                book['jiesao'] = jiesao
                book['author'] = author
                book['count'] = count
                break

        return redirect('/book/home')


def delete(request):
    id = request.GET.get("id")
    for book in books:
        if book['id'] == id:
            books.remove(book)
            break

    return redirect('/book/home')


def to_charts(request):
    return render(request, "charts/index.html")


def to_me(request):
    return render(request, "book/me.html")


borrowing_records = [

]
borrowing_records.append({
    'id': "1",
    'user_name': 'User1',
    'book_name': '红楼梦',
    'borrow_date': '2023-10-01',
    'return_date': '2023-10-10',
    'borrow_count': 5,
})

borrowing_records.append({
    'id': "2",
    'user_name': 'User2',
    'book_name': '红岩',
    'borrow_date': '2023-10-02',
    'return_date': '2023-10-11',
    'borrow_count': 5,
})

borrowing_records.append({
    'id': "3",
    'user_name': 'User3',
    'book_name': '水浒传',
    'borrow_date': '2023-10-03',
    'return_date': '2023-10-12',
    'borrow_count': 5,
})

borrowing_records.append({
    'id': "4",
    'user_name': 'User4',
    'book_name': '三国演义',
    'borrow_date': '2023-10-04',
    'return_date': '2023-10-13',
    'borrow_count': 5,
})

borrowing_records.append({
    'id': "5",
    'user_name': 'User5',
    'book_name': '西游记',
    'borrow_date': '2023-10-05',
    'return_date': '2023-10-14',
    'borrow_count': 5,
})

borrowing_records.append({
    'id': "6",
    'user_name': 'User6',
    'book_name': '红楼梦',
    'borrow_date': '2023-10-06',
    'return_date': '2023-10-15',
    'borrow_count': 5,
})

borrowing_records.append({
    'id': "7",
    'user_name': 'User7',
    'book_name': '三国演义',
    'borrow_date': '2023-10-07',
    'return_date': '2023-10-16',
    'borrow_count': 5,
})


def initBorrowingRecords():
    return borrowing_records


def index_borrow(request):
    return render(request, 'book/borrow.html', {'records': initBorrowingRecords()})

配置setting.py

"""
Django settings for bookSystem project.

Generated by 'django-admin startproject' using Django 4.2.6.

For more information on this file, see
https://docs.djangoproject.com/en/4.2/topics/settings/

For the full list of settings and their values, see
https://docs.djangoproject.com/en/4.2/ref/settings/
"""
import os
from pathlib import Path

# Build paths inside the project like this: BASE_DIR / 'subdir'.
BASE_DIR = Path(__file__).resolve().parent.parent


# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/4.2/howto/deployment/checklist/

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = 'django-insecure-)ppzeenho%v0e449zk0xf$dk@&*2#3%0!)bo*9$yb2_t39w$2h'

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True

ALLOWED_HOSTS = []


# Application definition

INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'books'
]

MIDDLEWARE = [
    'django.middleware.security.SecurityMiddleware',
    'django.contrib.sessions.middleware.SessionMiddleware',
    'django.middleware.common.CommonMiddleware',
    'django.middleware.csrf.CsrfViewMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    'django.contrib.messages.middleware.MessageMiddleware',
    'django.middleware.clickjacking.XFrameOptionsMiddleware',
]

ROOT_URLCONF = 'bookSystem.urls'

TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [BASE_DIR / 'templates']
        ,
        'APP_DIRS': True,
        'OPTIONS': {
            'context_processors': [
                'django.template.context_processors.debug',
                'django.template.context_processors.request',
                'django.contrib.auth.context_processors.auth',
                'django.contrib.messages.context_processors.messages',
            ],
        },
    },
]

WSGI_APPLICATION = 'bookSystem.wsgi.application'


# Database
# https://docs.djangoproject.com/en/4.2/ref/settings/#databases


# DATABASES = {
#     'default': {
#         'ENGINE': 'django.db.backends.mysql',
#         'NAME': 'book',
#         'USER': 'root',
#         'PASSWORD': 'gdh1597',
#         'HOST': '127.0.0.1',
#         'PORT': 3306,
#         'CHARSET': 'utf8',
#     }
# }


# Password validation
# https://docs.djangoproject.com/en/4.2/ref/settings/#auth-password-validators

AUTH_PASSWORD_VALIDATORS = [
    {
        'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
    },
    {
        'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
    },
    {
        'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
    },
    {
        'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
    },
]


# Internationalization
# https://docs.djangoproject.com/en/4.2/topics/i18n/

LANGUAGE_CODE = 'en-us'

TIME_ZONE = 'UTC'

USE_I18N = True

USE_TZ = True


# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/4.2/howto/static-files/

''' STATIC_URL用于配置指定通过那个URL地址访问静态文件'''
STATIC_URL = '/static/'  # http://127.0.0.1:8000/statics/
''' STATICFILES_DIRS 用于配置静态文件的存储路径,即静态文件在服务器端的存储位置'''
STATICFILES_DIRS = (os.path.join(BASE_DIR, 'static'),)  # 元组

# Default primary key field type
# https://docs.djangoproject.com/en/4.2/ref/settings/#default-auto-field

DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'

完整源码下载:https://download.csdn.net/download/FL1768317420/89208366

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

FL1768317420

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值