diff --git a/reallibrary/settings.py b/reallibrary/settings.py index 34d4272..c348352 100644 --- a/reallibrary/settings.py +++ b/reallibrary/settings.py @@ -12,10 +12,11 @@ import os -from dotenv import load_dotenv + +#from dotenv import load_dotenv from pathlib import Path -load_dotenv() +#load_dotenv() # Build paths inside the project like this: BASE_DIR / 'subdir'. BASE_DIR = Path(__file__).resolve().parent.parent @@ -45,6 +46,7 @@ "django.contrib.sessions", "django.contrib.messages", "django.contrib.staticfiles", + "web.apps.WebConfig", ] MIDDLEWARE = [ @@ -55,6 +57,7 @@ "django.contrib.auth.middleware.AuthenticationMiddleware", "django.contrib.messages.middleware.MessageMiddleware", "django.middleware.clickjacking.XFrameOptionsMiddleware", + ] ROOT_URLCONF = "reallibrary.urls" @@ -84,11 +87,11 @@ DATABASES = { "default": { "ENGINE": "django.db.backends.mysql", - "NAME": os.environ.get("MYSQL_DATABASE"), - "HOST": os.environ.get("MYSQL_DATABASE_HOST"), - "PORT": os.environ.get("MYSQL_DATABASE_PORT"), - "USER": os.environ.get("MYSQL_USER"), - "PASSWORD": os.environ.get("MYSQL_PASSWORD"), + "NAME": 'FinalDemo', + "HOST": '127.0.0.1', + "PORT": '3306', + "USER": 'root', + "PASSWORD": 'liuyuyang', } } @@ -127,7 +130,12 @@ # Static files (CSS, JavaScript, Images) # https://docs.djangoproject.com/en/4.0/howto/static-files/ -STATIC_URL = "static/" +STATIC_URL = '/static/' + +STATICFILES_DIRS = [ + os.path.join(BASE_DIR, 'static'), +] + # Default primary key field type # https://docs.djangoproject.com/en/4.0/ref/settings/#default-auto-field diff --git a/reallibrary/urls.py b/reallibrary/urls.py index f41f3c3..2e5cc1f 100644 --- a/reallibrary/urls.py +++ b/reallibrary/urls.py @@ -16,9 +16,17 @@ from django.contrib import admin from django.urls import include, path +from web.views import index,logins,regist,log_out +from reallibrary import settings +from django.conf.urls.static import static + urlpatterns = [ path("events/", include("events.urls")), path("inventory/", include("inventory.urls")), path("rooms/", include("rooms.urls")), path("admin/", admin.site.urls), + path("",index,name='home_page'), + path("regist/",regist,name='regist_page'), + path("login/",logins,name="log_in_page"), + path("logout/",log_out) ] diff --git a/web/__init__.py b/web/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/web/admin.py b/web/admin.py new file mode 100644 index 0000000..8c38f3f --- /dev/null +++ b/web/admin.py @@ -0,0 +1,3 @@ +from django.contrib import admin + +# Register your models here. diff --git a/web/apps.py b/web/apps.py new file mode 100644 index 0000000..c11daac --- /dev/null +++ b/web/apps.py @@ -0,0 +1,6 @@ +from django.apps import AppConfig + + +class WebConfig(AppConfig): + default_auto_field = "django.db.models.BigAutoField" + name = "web" diff --git a/web/migrations/__init__.py b/web/migrations/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/web/models.py b/web/models.py new file mode 100644 index 0000000..71a8362 --- /dev/null +++ b/web/models.py @@ -0,0 +1,3 @@ +from django.db import models + +# Create your models here. diff --git a/web/static/img/library.jpg b/web/static/img/library.jpg new file mode 100644 index 0000000..ad8ce6d Binary files /dev/null and b/web/static/img/library.jpg differ diff --git a/web/static/img/publications.png b/web/static/img/publications.png new file mode 100644 index 0000000..b804087 Binary files /dev/null and b/web/static/img/publications.png differ diff --git a/web/templates/index.html b/web/templates/index.html new file mode 100644 index 0000000..97639ab --- /dev/null +++ b/web/templates/index.html @@ -0,0 +1,68 @@ +{%load static%} + + + + + + + + Home Page + + + + + +
+ My image +
+ + + +
+
+ + +
+
+ + + + + + + + + \ No newline at end of file diff --git a/web/templates/login.html b/web/templates/login.html new file mode 100644 index 0000000..d71ac3d --- /dev/null +++ b/web/templates/login.html @@ -0,0 +1,38 @@ + + + + + + + + Log in + + + +
+
+
+
+
+
+ {%csrf_token%} +

{{msg}}

+
+ + +
+
+ + +
+ +
+
+
+
+
+
+ + + + \ No newline at end of file diff --git a/web/templates/regist.html b/web/templates/regist.html new file mode 100644 index 0000000..bcf2589 --- /dev/null +++ b/web/templates/regist.html @@ -0,0 +1,46 @@ + + + + + + + + 注册 + + + +
+
+
+
+
+
+ {%csrf_token%} +

{{msg}}

+
+ + +
+
+ + +
+
+ + +
+
+ + +
+ +
+
+
+
+
+ +
+ + + \ No newline at end of file diff --git a/web/tests.py b/web/tests.py new file mode 100644 index 0000000..7ce503c --- /dev/null +++ b/web/tests.py @@ -0,0 +1,3 @@ +from django.test import TestCase + +# Create your tests here. diff --git a/web/views.py b/web/views.py new file mode 100644 index 0000000..ce9e4e7 --- /dev/null +++ b/web/views.py @@ -0,0 +1,47 @@ + +from django.shortcuts import render, redirect +from django.contrib.auth.models import User +from django.contrib.auth import authenticate,login,logout +# Create your views here. +def index(request): + return render(request,'index.html') + +def logins(request): + if(request.method=='POST'): + username=request.POST.get('username') + password=request.POST.get('password') + user=authenticate(username=username,password=password) + if user: + login(request,user) + return redirect('/') + else: + msg=('Incorrect Password') + return render(request,'login.html',locals()) + return render(request,'login.html') + + +def regist(request): + if(request.method=='POST'): + username=request.POST.get('username') + password=request.POST.get('password') + password2=request.POST.get('password2') + email=request.POST.get('email') + if(password!=password2): + msg='the confirmed password not matched' + return render(request,'regist.html',locals()) + elif username=='': + msg='password should not be null' + return render(request,'regist.html',locals()) + cuser=User.objects.create_user(username=username,password=password,email=email) + cuser.save() + return redirect('/login/') + return render(request,'regist.html') + + +def log_out(request): + logout(request) + return redirect('/') + + + +