From cf503387b79207f9b47cc40d1b8ad62d610ecc73 Mon Sep 17 00:00:00 2001 From: lzh <52725224+Yourdaylight@users.noreply.github.com> Date: Tue, 14 Jul 2020 01:45:19 +0800 Subject: [PATCH] fixed some bugs --- ChatSystem聊天系统/Django_study/settings.py | 4 ++-- ChatSystem聊天系统/Django_study/urls.py | 4 +++- ChatSystem聊天系统/Django_study/views.py | 11 ++++++----- ChatSystem聊天系统/static/index.html | 4 +++- ChatSystem聊天系统/static/main.html | 2 +- 5 files changed, 15 insertions(+), 10 deletions(-) diff --git a/ChatSystem聊天系统/Django_study/settings.py b/ChatSystem聊天系统/Django_study/settings.py index 55c2cb6..7983e65 100644 --- a/ChatSystem聊天系统/Django_study/settings.py +++ b/ChatSystem聊天系统/Django_study/settings.py @@ -43,7 +43,7 @@ MIDDLEWARE = [ 'django.middleware.security.SecurityMiddleware', 'django.contrib.sessions.middleware.SessionMiddleware', 'django.middleware.common.CommonMiddleware', - 'django.middleware.csrf.CsrfViewMiddleware', + # 'django.middleware.csrf.CsrfViewMiddleware', 'django.contrib.auth.middleware.AuthenticationMiddleware', 'django.contrib.messages.middleware.MessageMiddleware', 'django.middleware.clickjacking.XFrameOptionsMiddleware', @@ -54,7 +54,7 @@ ROOT_URLCONF = 'Django_study.urls' TEMPLATES = [ { 'BACKEND': 'django.template.backends.django.DjangoTemplates', - 'DIRS': [os.path.join(BASE_DIR, 'templates')] + 'DIRS': [os.path.join(BASE_DIR, 'static')] , 'APP_DIRS': True, 'OPTIONS': { diff --git a/ChatSystem聊天系统/Django_study/urls.py b/ChatSystem聊天系统/Django_study/urls.py index c30cd72..cb613dd 100644 --- a/ChatSystem聊天系统/Django_study/urls.py +++ b/ChatSystem聊天系统/Django_study/urls.py @@ -19,7 +19,9 @@ from django.http import HttpResponse from django.conf.urls import url from Django_study import views + urlpatterns = [ - url(r'^$', views.home), + path('',views.home), + path(r'main.html/', views.home2,name='main'), path('admin/', admin.site.urls), ] diff --git a/ChatSystem聊天系统/Django_study/views.py b/ChatSystem聊天系统/Django_study/views.py index f765aa5..7b6b79c 100644 --- a/ChatSystem聊天系统/Django_study/views.py +++ b/ChatSystem聊天系统/Django_study/views.py @@ -1,10 +1,11 @@ import os from django.http import HttpResponse from django.conf import settings +from django.views.decorators.csrf import csrf_exempt +from django.shortcuts import render, reverse, redirect def home(request): - path=os.path.join(settings.BASE_DIR,'static','index.html') - html='' - with open(path,'r',encoding='utf-8') as f : - html=f.read() + return render(request,'../static/index.html') - return HttpResponse(html) \ No newline at end of file + +def home2(request): + return render(request,'../static/main.html') \ No newline at end of file diff --git a/ChatSystem聊天系统/static/index.html b/ChatSystem聊天系统/static/index.html index 951b5d2..19b593b 100644 --- a/ChatSystem聊天系统/static/index.html +++ b/ChatSystem聊天系统/static/index.html @@ -34,7 +34,9 @@ -
+ + +

在线聊天系统

diff --git a/ChatSystem聊天系统/static/main.html b/ChatSystem聊天系统/static/main.html index c0aedf3..ba6558d 100644 --- a/ChatSystem聊天系统/static/main.html +++ b/ChatSystem聊天系统/static/main.html @@ -28,7 +28,7 @@