first commit

main
谢英豪 6 months ago
parent 11b94ca837
commit b2067b631a

8
.idea/.gitignore vendored

@ -0,0 +1,8 @@
# 默认忽略的文件
/shelf/
/workspace.xml
# 基于编辑器的 HTTP 客户端请求
/httpRequests/
# Datasource local storage ignored files
/dataSources/
/dataSources.local.xml

@ -0,0 +1,30 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="PYTHON_MODULE" version="4">
<component name="FacetManager">
<facet type="django" name="Django">
<configuration>
<option name="rootFolder" value="$MODULE_DIR$" />
<option name="settingsModule" value="DjangoBlogs/settings.py" />
<option name="manageScript" value="$MODULE_DIR$/manage.py" />
<option name="environment" value="&lt;map/&gt;" />
<option name="doNotUseTestRunner" value="false" />
<option name="trackFilePattern" value="migrations" />
</configuration>
</facet>
</component>
<component name="NewModuleRootManager">
<content url="file://$MODULE_DIR$">
<excludeFolder url="file://$MODULE_DIR$/.venv" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
<component name="TemplatesService">
<option name="TEMPLATE_CONFIGURATION" value="Django" />
<option name="TEMPLATE_FOLDERS">
<list>
<option value="$MODULE_DIR$/../DjangoBlogs\templates" />
</list>
</option>
</component>
</module>

@ -0,0 +1,6 @@
<component name="InspectionProjectProfileManager">
<settings>
<option name="USE_PROJECT_PROFILE" value="false" />
<version value="1.0" />
</settings>
</component>

@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="Black">
<option name="sdkName" value="Python 3.12 (DjangoBlogs)" />
</component>
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.12 (DjangoBlogs)" project-jdk-type="Python SDK" />
</project>

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/.idea/DjangoBlogs.iml" filepath="$PROJECT_DIR$/.idea/DjangoBlogs.iml" />
</modules>
</component>
</project>

@ -0,0 +1,16 @@
"""
ASGI config for DjangoBlogs 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', 'DjangoBlogs.settings')
application = get_asgi_application()

@ -0,0 +1,145 @@
"""
Django settings for DjangoBlogs 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!
SECRET_KEY = 'django-insecure-atkxm8*x$-8&nk=_ehs(pgq_w$40$#%5b_fnl_u0bu4x+p*4g='
# 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',
'blog',
'auth1'
]
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 = 'DjangoBlogs.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',
],
#加载静态文件static
'builtins':['django.templatetags.static']
},
},
]
WSGI_APPLICATION = 'DjangoBlogs.wsgi.application'
# Database
# https://docs.djangoproject.com/en/5.0/ref/settings/#databases
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'OPTIONS': {
'read_default_file': 'my.cnf',
},
}
}
# 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/'
#静态文件加载路径
STATICFILES_DIRS = [
BASE_DIR / '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'
EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
EMAIL_USE_TLS = True
EMAIL_HOST = 'smtp.qq.com'
EMAIL_PORT = 587
EMAIL_HOST_USER = '3485393348@qq.com'
EMAIL_HOST_PASSWORD = 'grjwnwpflcohdagg'
DEFAULT_FROM_EMAIL = '3485393348@qq.com'

@ -0,0 +1,27 @@
"""
URL configuration for DjangoBlogs 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, include
from django.shortcuts import HttpResponse
##HttpResponse 对象是一个非常常见的响应类型,表示一个简单的文本或 HTML 响应。可以使用 HttpResponse 对象返回字符串、HTML 页面或任何其他类型的文本数据,例如 JSON 数据、XML 数据等。
urlpatterns = [
path('admin/', admin.site.urls),
path('', include('blog.urls')),
path('auth/', include('auth1.urls'))
]

@ -0,0 +1,16 @@
"""
WSGI config for DjangoBlogs 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', 'DjangoBlogs.settings')
application = get_wsgi_application()

@ -0,0 +1,3 @@
from django.contrib import admin
# Register your models here.

@ -0,0 +1,6 @@
from django.apps import AppConfig
class Auth1Config(AppConfig):
default_auto_field = 'django.db.models.BigAutoField'
name = 'auth1'

@ -0,0 +1,23 @@
# Generated by Django 5.0.6 on 2024-05-22 17:02
from django.db import migrations, models
class Migration(migrations.Migration):
initial = True
dependencies = [
]
operations = [
migrations.CreateModel(
name='CaptchaModel',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('email', models.EmailField(max_length=254)),
('captcha', models.CharField(max_length=4)),
('created_time', models.DateTimeField(auto_now_add=True)),
],
),
]

@ -0,0 +1,18 @@
# Generated by Django 5.0.6 on 2024-05-22 17:46
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('auth1', '0001_initial'),
]
operations = [
migrations.AlterField(
model_name='captchamodel',
name='email',
field=models.EmailField(max_length=254, unique=True),
),
]

@ -0,0 +1,8 @@
from django.db import models
# Create your models here.
class CaptchaModel(models.Model):
email = models.EmailField(unique=True)
captcha = models.CharField(max_length=4)
created_time = models.DateTimeField(auto_now_add=True)

@ -0,0 +1,3 @@
from django.test import TestCase
# Create your tests here.

@ -0,0 +1,10 @@
from django.urls import path
from .import views
app_name = 'auth1'
urlpatterns=[
path('login',views.login, name='login'),
path('register',views.register, name='register'),
path('captcha', views.send_email_captcha, name='email_captcha')
]

@ -0,0 +1,26 @@
from django.shortcuts import render
from django.http.response import JsonResponse
import string
import random
from django.core.mail import send_mail
from .models import CaptchaModel
# Create your views here.
def login(request):
return render(request, 'login.html')
def register(request):
return render(request, 'register.html')
def send_email_captcha(request):
email = request.GET.get('email')
if not email:
return JsonResponse({'code': 400, 'message': '请输入邮箱'})
# 生成验证码
captcha ="".join(random.sample(string.digits, 4))
CaptchaModel.objects.update_or_create(email=email, defaults={'captcha': captcha})
send_mail("湖南工业大学论坛验证码", message=f"你的验证码是{captcha}", recipient_list=[email], from_email='3485393348@qq.com')
return JsonResponse({'code': 200, 'message': '发送成功'})

@ -0,0 +1,3 @@
from django.contrib import admin
# Register your models here.

@ -0,0 +1,6 @@
from django.apps import AppConfig
class BlogConfig(AppConfig):
default_auto_field = 'django.db.models.BigAutoField'
name = 'blog'

@ -0,0 +1,3 @@
from django.db import models
# Create your models here.

@ -0,0 +1,3 @@
from django.test import TestCase
# Create your tests here.

@ -0,0 +1,10 @@
from django.urls import path
from . import views
app_name = 'blog'
urlpatterns = [
path('', views.index, name='index'),
path('blog/detail/<blog_id>', views.blog_detail, name='blog_detail'),
path('blog/pub', views.pub_blog, name='pub_blog'),
]

@ -0,0 +1,11 @@
from django.shortcuts import render
# Create your views here.
def index(request):
return render(request, 'index.html')
def blog_detail(request, blog_id):
return render(request,'blog_detail.html')
def pub_blog(request):
return render(request,'pub_blog.html')

@ -0,0 +1,22 @@
#!/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', 'DjangoBlogs.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()

@ -0,0 +1,5 @@
[client]
database = djangoblog
user = root
password = huixia1222
default-character-set = utf8

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

@ -0,0 +1,3 @@
body{
background-color: rgba(0, 0, 0, 0.1);
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 11 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 24 KiB

File diff suppressed because one or more lines are too long

@ -0,0 +1,28 @@
window.onload = function () {
const {createEditor, createToolbar} = window.wangEditor
const editorConfig = {
placeholder: 'Type here...',
onChange(editor) {
const html = editor.getHtml()
console.log('editor content', html)
// 也可以同步到 <textarea>
}
}
const editor = createEditor({
selector: '#editor-container',
html: '<p><br></p>',
config: editorConfig,
mode: 'default', // or 'simple'
})
const toolbarConfig = {}
const toolbar = createToolbar({
editor,
selector: '#toolbar-container',
config: toolbarConfig,
mode: 'default', // or 'simple'
})
}

@ -0,0 +1,45 @@
$(function () {
function bindCaptchaBtnClick() {
$("#captcha-btn").click(function (event) {
let $this = $(this);
let email = $("input[name='email']").val();
if (!email) {
alert("请输入邮箱");
return;
}
$this.off("click");
$.ajax('/auth/captcha?email='+email,{
method: "GET",
success: function (result) {
if (result.code === 200) {
alert("验证码发送成功");
}else {
alert(result['message']);
}
console.log(result);
},
fail: function (error) {
console.log(error);
}
})
let countdown = 6;
let timer = setInterval(function () {
if (countdown <= 0) {
$this.text("发送验证码");
clearInterval(timer);
bindCaptchaBtnClick();
} else {
countdown--;
$this.text(countdown + "s");
}
}, 1000);
})
}
bindCaptchaBtnClick();
});

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

@ -0,0 +1,44 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>{% block title %}{% endblock %}</title>
<link rel="stylesheet" href=" {% static 'bootstrap5/bootstrap.min.css' %}">
<script src=" {% static 'bootstrap5/popper.min.js' %}"></script>
<script src=" {% static 'bootstrap5/bootstrap.min.js' %}"></script>
<link rel="stylesheet" href=" {% static 'css/base.css' %}">
{% block head %}{% endblock %}
</head>
<body>
<header class="p-3 text-bg-secondary border-bottom mb-3">
<div class="container">
<div class="d-flex flex-wrap align-items-center justify-content-center justify-content-lg-start">
<a href="/" class="d-flex align-items-center mb-2 mb-lg-0 text-white text-decoration-none">
<img src="{% static 'image/logo1.png' %}" alt="">
</a>
<ul class="nav col-12 col-lg-auto me-lg-auto mb-2 justify-content-center mb-md-0">
<li><a href="#" class="nav-link px-2 text-white">论坛首页</a></li>
<li><a href="#" class="nav-link px-2 text-white">发布</a></li>
<li><a href="#" class="nav-link px-2 text-white">Pricing</a></li>
<li><a href="#" class="nav-link px-2 text-white">FAQs</a></li>
<li><a href="#" class="nav-link px-2 text-white">About</a></li>
</ul>
<form class="col-12 col-lg-auto mb-3 mb-lg-0 me-lg-3" role="search">
<input type="search" class="form-control form-control-dark text-white" placeholder="搜索..."
aria-label="Search" _mstplaceholder="99723" _mstaria-label="74607">
</form>
<div class="text-end">
<button type="button" class="btn btn-outline-light me-2">登录</button>
<button type="button" class="btn btn-outline-light me-2">注册</button>
</div>
</div>
</div>
</header>
<main class="container bg-white p-3 rounded">
{% block main %}{% endblock %}
</main>
</body>
</html>

@ -0,0 +1,46 @@
{% extends 'base.html' %}
{% block main %}
<h1>我是标题</h1>
<hr>
<div class="mt-2">
<img src="{% static 'image/profile.png' %}" class="rounded-circle " width="30" height="30" alt="">
<span class="mt-2">huixia</span>
<span class="mt-2"></span>
<span class="mt-2">21点22分</span>发布
<hr>
<div class="py-2">
我是内容234111111111111111111111845893081934
</div>
<hr>
<div class="mt-2">
<h3>评论:</h3>
<form action="" method="POST">
<div class="mt-2">
<input type="text" class="form-control" placeholder="请输入评论">
</div>
<div class="text-end mt-3">
<button type="button" class="btn btn-primary">发送</button>
</div>
</form>
</div>
<div class="mt-2">
<ul class="list-group list-group-flush">
<li class="list-group-item mb-3">
<div class="d-flex justify-content-between text-body-tertiary">
<div class="user-info">
<img src="{% static 'image/profile.png' %}" class="rounded-circle " width="40" height="40"
alt="">
<span class="ms-2">huixia</span>
</div>
<div class="create-time">01点16分</div>
</div>
<div class="mt-2">
我是评论内容
</div>
</li>
</ul>
</div>
</div>
{% endblock %}

@ -0,0 +1,10 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
</body>
</html>

@ -0,0 +1,26 @@
{% extends 'base.html' %}
{% block title %}论坛首页111{% endblock %}
{% block main %}
<h1>文章列表</h1>
<div class="row row-cols-2 row-gap-4">
<div class="col">
<div class="card">
<div class="card-header">
我是标题
</div>
<div class="card-body" style="height: 140px">
<p class="card-text">我是内容234111111111111111111111845893081934</p>
</div>
<div class="card-footer text-body-secondary d-flex justify-content-between">
<div>
<img src="{% static 'image/profile.png' %}" class="rounded-circle " width="30" height="30" alt="">
huixia
</div>
<div>20点40分</div>
</div>
</div>
</div>
</div>
{% endblock %}

@ -0,0 +1,28 @@
{% extends 'base.html' %}
{% block title %}登录界面{% endblock %}
{% block main %}
<div style="max-width: 400px;" class="m-auto">
<h1>登录</h1>
<form action="" method="POST">
<div class="mb-3">
<label>邮箱</label>
<input type="email" name="email" class="form-control" placeholder="请输入邮箱">
</div>
<div class="mb-3">
<label>密码</label>
<input type="password" name="password" class="form-control" placeholder="请输入密码">
</div>
<div class="form-check mb-3">
<input class="form-check-input" type="checkbox" name="remember" value="1" id="flexCheckDefault">
<label class="form-check-label" for="flexCheckDefault">
记住我
</label>
</div>
<div class="mb-3">
<button class="btn btn-primary ">立即登录</button>
</div>
</form>
</div>
{% endblock %}

@ -0,0 +1,56 @@
{% extends 'base.html' %}
{% block title %}发布帖子{% endblock %}
{% block head %}
<link rel="stylesheet" href=" {% static 'wangeditor/style.css' %}">
<script src=" {% static 'wangeditor/index.js' %}"></script>
<script src=" {% static 'js/pub_blog.js' %}"></script>
<style>
#editor—wrapper {
border: 1px solid #ccc;
z-index: 100; /* 按需定义 */
}
#toolbar-container {
border-bottom: 1px solid #ccc;
}
#editor-container {
height: 400px;
}
</style>
{% endblock %}
{% block main %}
<h1>发布帖子</h1>
<div class="mt-3">
<form action="" method="POST">
<div class="mb-3">
<label class="form-label">标题</label>"
<input type="text" name="title" class="form-control">
</div>
<div class="mb-3">
<label class="form-label">分类</label>"
<select name="category" class="form-select">
<option value="1">校园事件</option>
<option value="2">课题讨论</option>
<option value="3">生活分享</option>
<option value="4">失物招领</option>
<option value="5">CPDD</option>
</select>
</div>
<div class="mb-3">
<label class="form-label">我是内容</label>
<div id="editor—wrapper">
<div id="toolbar-container"><!-- 工具栏 --></div>
<div id="editor-container"><!-- 编辑器 --></div>
</div>
</div>
<div class="mb-3 text-end">
<button class="btn btn-primary">发布</button>
</div>
</form>
</div>
{% endblock %}

@ -0,0 +1,56 @@
{% extends 'base.html' %}
{% block title %}注册页面{% endblock %}
{% block head %}
<script src="{% static 'jquery/jquery-3.7.1.min.js' %}"></script>
<script src="{% static 'js/register.js' %}"></script>
{% endblock %}
{% block main %}
<div style="max-width: 400px;" class="m-auto">
<h1>请注册</h1>
<form action="" method="POST">
<div class="mb-3">
<label>用户名</label>
<input type="text" name="username" class="form-control" placeholder="用户名">
</div>
<div class="mb-3">
<label>邮箱</label>
<input type="email" name="email" class="form-control" placeholder="请输入邮箱">
</div>
<div class="mb-3">
<label>密码</label>
<input type="password" name="password" class="form-control" placeholder="请输入密码">
</div>
<div class="mb-3">
<label>验证码</label>
<div class="input-group ">
<input type="text" class="form-control" placeholder="请输入验证码"
aria-label="Recipient's username" aria-describedby="button-addon2">
<button class="btn btn-outline-secondary" type="button" id="captcha-btn">获取验证码</button></div>
</div>
<div class="mb-3">
<button class="btn btn-primary ">立即注册</button>
</div>
</form>
</div>
{% endblock %}
Loading…
Cancel
Save