diff --git a/djangoProject1/.idea/.gitignore b/djangoProject1/.idea/.gitignore deleted file mode 100644 index 35410ca..0000000 --- a/djangoProject1/.idea/.gitignore +++ /dev/null @@ -1,8 +0,0 @@ -# 默认忽略的文件 -/shelf/ -/workspace.xml -# 基于编辑器的 HTTP 客户端请求 -/httpRequests/ -# Datasource local storage ignored files -/dataSources/ -/dataSources.local.xml diff --git a/djangoProject1/.idea/dataSources.xml b/djangoProject1/.idea/dataSources.xml deleted file mode 100644 index 27223a9..0000000 --- a/djangoProject1/.idea/dataSources.xml +++ /dev/null @@ -1,20 +0,0 @@ - - - - - sqlite.xerial - true - org.sqlite.JDBC - jdbc:sqlite:C:\Users\aurora\PycharmProjects\login_manager\db.sqlite3 - $ProjectFileDir$ - - - file://$APPLICATION_CONFIG_DIR$/jdbc-drivers/Xerial SQLiteJDBC/3.45.1/org/xerial/sqlite-jdbc/3.45.1.0/sqlite-jdbc-3.45.1.0.jar - - - file://$APPLICATION_CONFIG_DIR$/jdbc-drivers/Xerial SQLiteJDBC/3.45.1/org/slf4j/slf4j-api/1.7.36/slf4j-api-1.7.36.jar - - - - - \ No newline at end of file diff --git a/djangoProject1/.idea/djangoProject1.iml b/djangoProject1/.idea/djangoProject1.iml deleted file mode 100644 index dd7d03f..0000000 --- a/djangoProject1/.idea/djangoProject1.iml +++ /dev/null @@ -1,28 +0,0 @@ - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/djangoProject1/.idea/inspectionProfiles/Project_Default.xml b/djangoProject1/.idea/inspectionProfiles/Project_Default.xml deleted file mode 100644 index 2872f29..0000000 --- a/djangoProject1/.idea/inspectionProfiles/Project_Default.xml +++ /dev/null @@ -1,15 +0,0 @@ - - - - \ No newline at end of file diff --git a/djangoProject1/.idea/inspectionProfiles/profiles_settings.xml b/djangoProject1/.idea/inspectionProfiles/profiles_settings.xml deleted file mode 100644 index 105ce2d..0000000 --- a/djangoProject1/.idea/inspectionProfiles/profiles_settings.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - \ No newline at end of file diff --git a/djangoProject1/.idea/misc.xml b/djangoProject1/.idea/misc.xml deleted file mode 100644 index 9de2865..0000000 --- a/djangoProject1/.idea/misc.xml +++ /dev/null @@ -1,7 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/djangoProject1/.idea/modules.xml b/djangoProject1/.idea/modules.xml deleted file mode 100644 index ba74f8e..0000000 --- a/djangoProject1/.idea/modules.xml +++ /dev/null @@ -1,8 +0,0 @@ - - - - - - - - \ No newline at end of file diff --git a/djangoProject1/demo/__init__.py b/djangoProject1/demo/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/djangoProject1/demo/admin.py b/djangoProject1/demo/admin.py deleted file mode 100644 index 8c38f3f..0000000 --- a/djangoProject1/demo/admin.py +++ /dev/null @@ -1,3 +0,0 @@ -from django.contrib import admin - -# Register your models here. diff --git a/djangoProject1/demo/apps.py b/djangoProject1/demo/apps.py deleted file mode 100644 index 6fbee78..0000000 --- a/djangoProject1/demo/apps.py +++ /dev/null @@ -1,6 +0,0 @@ -from django.apps import AppConfig - - -class DemoConfig(AppConfig): - default_auto_field = "django.db.models.BigAutoField" - name = "demo" diff --git a/djangoProject1/demo/migrations/__init__.py b/djangoProject1/demo/migrations/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/djangoProject1/demo/models.py b/djangoProject1/demo/models.py deleted file mode 100644 index 71a8362..0000000 --- a/djangoProject1/demo/models.py +++ /dev/null @@ -1,3 +0,0 @@ -from django.db import models - -# Create your models here. diff --git a/djangoProject1/demo/tests.py b/djangoProject1/demo/tests.py deleted file mode 100644 index 7ce503c..0000000 --- a/djangoProject1/demo/tests.py +++ /dev/null @@ -1,3 +0,0 @@ -from django.test import TestCase - -# Create your tests here. diff --git a/djangoProject1/demo/views.py b/djangoProject1/demo/views.py deleted file mode 100644 index 9b0c170..0000000 --- a/djangoProject1/demo/views.py +++ /dev/null @@ -1,98 +0,0 @@ -from django.shortcuts import render,redirect -import pandas as pd -from sqlalchemy import create_engine -from sqlalchemy import Table, Column, Integer, String, MetaData -from sqlalchemy import select - - -mysql_host = 'localhost' -mysql_db = 'login' -mysql_user = 'root' -mysql_pwd = '123456' -mysql_table = 'login' - - -def put_in_database(username,password): - engine = create_engine( - 'mysql+pymysql://{}:{}@{}:3306/{}?charset=utf8'.format(mysql_user, mysql_pwd, mysql_host, mysql_db)) - df = pd.DataFrame({ - 'user': [username], - 'password': [password], - }) - # 表名 - df.to_sql(mysql_table, con=engine, if_exists='append', index=False) - """ - to_sql参数:(比较重要) - if_exists:表如果存在怎么处理 - append:追加 - replace:删除原表,建立新表再添加 - fail:什么都不干 - chunksize: 默认的话是一次性导入, 给值的话是批量导入,一批次导入多少 - index=False:不插入索引index - dtype 创建表结构 - 需要导入 import sqlalchemy - dtype = {'id': sqlalchemy.types.BigInteger(), - 'name': sqlalchemy.types.String(length=20), - 'sex': sqlalchemy.types.String(length=20), - 'age': sqlalchemy.types.BigInteger(), - }) - - """ -def read_database(username, password): - engine = create_engine( - 'mysql+pymysql://{}:{}@{}:3306/{}?charset=utf8'.format(mysql_user, mysql_pwd, mysql_host, mysql_db)) - - #创建表 - metadata = MetaData() - - users = Table('login', metadata, - Column('index', Integer, primary_key=True), - Column('user', String), - Column('password', String) - ) - - metadata.create_all(engine) - - select_statement = users.select().where(users.c.user == username) - with engine.connect() as connection: - result_set = connection.execute(select_statement) - for index ,user,pwd in result_set: - if user == username and pwd == password: - return True - -def index(request): - info_dict=request.session.get('info') - if not info_dict: - return redirect('/login/') - return render(request,"index.html",{"info_dict":info_dict}) - - - -def login(request): - if request.method == "GET": - return render(request, "login.html") - else: - #从请求体中获取数据 - username = request.POST.get("user") - password = request.POST.get("password") - #数据库中校验 - if read_database(username, password): - #校验成功,生成随机字符串,返回到用户浏览器的cookie,存储网站的session - request.session["info"] = {"username": username, "password": password} - #跳转到后台管理页面 - return redirect("/index/") - else:#不成功返回并报告错误 - return render(request, 'login.html',{"error":"用户名或密码错误"}) - -def enroll(request): - if request.method == "GET": - return render(request, "enroll.html") - else: - #从请求体中获取数据 - username = request.POST.get("user") - password = request.POST.get("password") - #放入数据库中 - put_in_database(username,password) - return redirect("/login/") - -# Create your views here. diff --git a/djangoProject1/djangoProject1/__init__.py b/djangoProject1/djangoProject1/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/djangoProject1/djangoProject1/asgi.py b/djangoProject1/djangoProject1/asgi.py deleted file mode 100644 index 2ccd489..0000000 --- a/djangoProject1/djangoProject1/asgi.py +++ /dev/null @@ -1,16 +0,0 @@ -""" -ASGI config for djangoProject1 project. - -It exposes the ASGI callable as a module-level variable named ``application``. - -For more information on this file, see -https://docs.djangoproject.com/en/5.0/howto/deployment/asgi/ -""" - -import os - -from django.core.asgi import get_asgi_application - -os.environ.setdefault("DJANGO_SETTINGS_MODULE", "djangoProject1.settings") - -application = get_asgi_application() diff --git a/djangoProject1/djangoProject1/settings.py b/djangoProject1/djangoProject1/settings.py deleted file mode 100644 index 27dda64..0000000 --- a/djangoProject1/djangoProject1/settings.py +++ /dev/null @@ -1,131 +0,0 @@ -""" -Django settings for djangoProject1 project. - -Generated by 'django-admin startproject' using Django 5.0.6. - -For more information on this file, see -https://docs.djangoproject.com/en/5.0/topics/settings/ - -For the full list of settings and their values, see -https://docs.djangoproject.com/en/5.0/ref/settings/ -""" - -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/5.0/howto/deployment/checklist/ - -# SECURITY WARNING: keep the secret key used in production secret! - - -# 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", -] - -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 = "djangoProject1.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 = "djangoProject1.wsgi.application" - - -# Database -# https://docs.djangoproject.com/en/5.0/ref/settings/#databases - -DATABASES = { - 'default': { - 'ENGINE': 'django.db.backends.sqlite3', # 或其他数据库后端 - 'NAME': '../login_manager/db.sqlite3', - 'PASSWORD': '123', - 'HOST': 'localhost', - 'PORT': '3307', - } -} - -SECRET_KEY = "django-insecure-lykml8(#%eq-#g(@!k0w71gn3qfd04pyn659yio@$ml#teji6$" - -SESSION_ENGINE = 'django.contrib.sessions.backends.db' -SESSION_COOKIE_NAME = 'sessionid' # 默认值,你可以根据需要更改 - -# Password validation -# https://docs.djangoproject.com/en/5.0/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/5.0/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/5.0/howto/static-files/ - -STATIC_URL = "static/" - -# Default primary key field type -# https://docs.djangoproject.com/en/5.0/ref/settings/#default-auto-field - -DEFAULT_AUTO_FIELD = "django.db.models.BigAutoField" diff --git a/djangoProject1/djangoProject1/urls.py b/djangoProject1/djangoProject1/urls.py deleted file mode 100644 index d65c2a1..0000000 --- a/djangoProject1/djangoProject1/urls.py +++ /dev/null @@ -1,25 +0,0 @@ -""" -URL configuration for login_manager project. - -The `urlpatterns` list routes URLs to views. For more information please see: - https://docs.djangoproject.com/en/5.0/topics/http/urls/ -Examples: -Function views - 1. Add an import: from my_app import views - 2. Add a URL to urlpatterns: path('', views.home, name='home') -Class-based views - 1. Add an import: from other_app.views import Home - 2. Add a URL to urlpatterns: path('', Home.as_view(), name='home') -Including another URLconf - 1. Import the include() function: from django.urls import include, path - 2. Add a URL to urlpatterns: path('blog/', include('blog.urls')) -""" -from django.contrib import admin -from django.urls import path -from demo import views -urlpatterns = [ - path("admin/", admin.site.urls), - path("login/", views.login), - path("index/", views.index), - path("enroll/",views.enroll), -] diff --git a/djangoProject1/djangoProject1/wsgi.py b/djangoProject1/djangoProject1/wsgi.py deleted file mode 100644 index 25342aa..0000000 --- a/djangoProject1/djangoProject1/wsgi.py +++ /dev/null @@ -1,16 +0,0 @@ -""" -WSGI config for djangoProject1 project. - -It exposes the WSGI callable as a module-level variable named ``application``. - -For more information on this file, see -https://docs.djangoproject.com/en/5.0/howto/deployment/wsgi/ -""" - -import os - -from django.core.wsgi import get_wsgi_application - -os.environ.setdefault("DJANGO_SETTINGS_MODULE", "djangoProject1.settings") - -application = get_wsgi_application() diff --git a/djangoProject1/manage.py b/djangoProject1/manage.py deleted file mode 100644 index 87276b1..0000000 --- a/djangoProject1/manage.py +++ /dev/null @@ -1,22 +0,0 @@ -#!/usr/bin/env python -"""Django's command-line utility for administrative tasks.""" -import os -import sys - - -def main(): - """Run administrative tasks.""" - os.environ.setdefault("DJANGO_SETTINGS_MODULE", "djangoProject1.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() diff --git a/djangoProject1/templates/enroll.html b/djangoProject1/templates/enroll.html deleted file mode 100644 index be0ee08..0000000 --- a/djangoProject1/templates/enroll.html +++ /dev/null @@ -1,39 +0,0 @@ -{% load static %} - - - - - Title - - - - -
-

用户注册

-
-
- - -
-
- - -
- -
-
- - \ No newline at end of file diff --git a/djangoProject1/templates/index.html b/djangoProject1/templates/index.html deleted file mode 100644 index 237d629..0000000 --- a/djangoProject1/templates/index.html +++ /dev/null @@ -1,12 +0,0 @@ -{% load static %} - - - - - Title - - - -

首页

- - \ No newline at end of file diff --git a/djangoProject1/templates/login.html b/djangoProject1/templates/login.html deleted file mode 100644 index c5009ce..0000000 --- a/djangoProject1/templates/login.html +++ /dev/null @@ -1,43 +0,0 @@ -{% load static %} - - - - - Title - - - - -
-

用户登录

-
-
- - -
-
- - -
- - {{ error }} -
-
- -
-
- - \ No newline at end of file