1.2.0 添加了sidebar的内容以及更多的网页,网页css有点混乱,需要进行更改

This commit is contained in:
yilv committed 2024-06-28 12:16:31 +08:00
1 parent 76777653cf
commit cdecded2a6
16 files changed
+414 -29

No files matched your search

Binary file not shown.
BIN
View File
Binary file not shown.
+18 -4
View File
@@ -1,25 +1,29 @@
#author jason
from flask import Flask, render_template, request, redirect, url_for, session, send_file
import sqlite3
import os
from captcha import generate_captcha
from datetime import timedelta
#init flask and database
app = Flask(__name__)
app.secret_key = 'your_secret_key'
DATABASE = 'app.db'
app.config['PERMANENT_SESSION_LIFETIME'] = timedelta(hours=1)
app.config['SESSION_COOKIE_SAMESITE'] = 'Lax'
def get_db_connection():
conn = sqlite3.connect(DATABASE)
conn.row_factory = sqlite3.Row
return conn
#index.html load the homepage(index.html) and load the information from database
@app.route('/')
def index():
conn = get_db_connection()
posts = conn.execute('SELECT * FROM posts ORDER BY created_at DESC').fetchall()
conn.close()
return render_template('index.html', posts=posts)
#signin.html load the page and get post from the form ,confirm users account and key
@app.route('/signin', methods=['GET', 'POST'])
def signin():
if request.method == 'POST':
@@ -44,6 +48,7 @@ def signin():
session['captcha'] = captcha_text
return render_template('signin.html', captcha_image=captcha_image)
#signup.html sign up and add accout and keys information into database
@app.route('/signup', methods=['GET', 'POST'])
def signup():
if request.method == 'POST':
@@ -56,7 +61,7 @@ def signup():
if password != confirm_password:
return 'Passwords do not match'
if captcha != session.get('captcha', ''):
if captcha != session.get('captcha', ''): #this part will be change ,give user a window ,rather than a new page
return 'Invalid captcha'
conn = get_db_connection()
@@ -82,6 +87,7 @@ def captcha():
session['captcha'] = captcha_text
return send_file(captcha_image, mimetype='image/png')
@app.route('/dashboard')
def dashboard():
if 'user' not in session:
@@ -134,6 +140,14 @@ def logout():
@app.route('/aboutus')
def aboutus():
return render_template('aboutus.html')
@app.route('/commands')
def commands():
return render_template('commands.html')
@app.route('/python')
def python():
return render_template('python.html')
@app.route('/video')
def video():
return render_template('video.html')
if __name__ == '__main__':
app.run(debug=True)
+1 -1
View File
@@ -9,7 +9,7 @@ def generate_captcha():
font = ImageFont.truetype("arial.ttf", 24)
draw = ImageDraw.Draw(image)
draw.text((10, 0), captcha_text, font=font, fill=(0, 0, 0))
buffer = BytesIO()
image.save(buffer, format="PNG")
buffer.seek(0)
+9
View File
@@ -0,0 +1,9 @@
<!-- This is a project based on flask -->
include pages:
index
signin
signup
dashboard
user
aboutus
BIN
View File
Binary file not shown.
+113
View File
@@ -0,0 +1,113 @@
/* 导航栏以及body样式 */
body {
font-family: Arial, sans-serif;
margin: 0;
padding: 0;
box-sizing: border-box;
}
header {
background-color: #333;
color: white;
padding: 10px 0;
text-align: right;
}
header nav ul {
list-style: none;
margin: 0;
padding: 0;
}
header nav ul li {
display: inline;
margin-right: 20px;
}
header nav ul li a {
color: white;
text-decoration: none;
}
main {
padding: 20px;
}
/* Footer 样式 */
.footer-container {
background-color: #333;
color: white;
padding: 20px 0;
display: flex;
justify-content: center;
align-items: center;
}
.footer-item {
margin: 0 20px;
}
.footer-item a {
color: white;
text-decoration: none;
font-weight: bold;
}
.footer-item a:hover {
color: #ddd;
}
/* 内容列表样式 */
#content-list {
margin-top: 20px;
}
.content-item {
border: 1px solid #ccc;
padding: 10px;
margin-bottom: 10px;
background-color: #f9f9f9;
display: flex;
justify-content: space-between;
align-items: center;
}
.content-item ul{
list-style-type: none;
}
.content-item ul li{
line-height: 2;
}
/*sidebar样式 */
.container {
display: flex;
}
.sidebar {
width: 250px;
background-color: #333;
color: white;
padding: 15px;
box-sizing: border-box;
height: 100vh;
position: fixed;
}
#content-list {
margin-left: 270px; /* 确保内容不会被侧边栏覆盖 */
padding: 20px;
box-sizing: border-box;
width: calc(100% - 270px);
}
.sidebar ul li a{
color: white;
}
.sidebar ul li {
padding: 10px;
text-align: left;
margin-bottom: 10px; /* 增加底部间距 */
}
+58 -2
View File
@@ -28,6 +28,11 @@ header nav ul li a {
color: white;
text-decoration: none;
}
/* header nav ul li:first-child{
float: left;
font-size: x-large;
} */
main {
padding: 20px;
@@ -79,6 +84,29 @@ button:hover {
font-weight: bold;
}
/* Footer 样式 */
.footer-container {
background-color: #333;
color: white;
padding: 20px 0;
display: flex;
justify-content: center;
align-items: center;
}
.footer-item {
margin: 0 20px;
}
.footer-item a {
color: white;
text-decoration: none;
font-weight: bold;
}
.footer-item a:hover {
color: #ddd;
}
/* Dashboard 样式 */
.dashboard {
max-width: 150%;
@@ -198,9 +226,7 @@ button:hover {
.user-posts {
margin-top: 20px;
}
.user-posts .content-item {
border: 1px solid #ccc;
padding: 10px;
margin-bottom: 10px;
background-color: #f9f9f9;
@@ -224,3 +250,33 @@ button:hover {
.logout-button:hover {
background-color: #555;
}
.container {
display: flex;
}
.sidebar {
width: 250px;
background-color: #333;
color: white;
padding: 15px;
box-sizing: border-box;
height: 100vh;
position: fixed;
}
#content-list {
margin-left: 270px; /* 确保内容不会被侧边栏覆盖 */
padding: 20px;
box-sizing: border-box;
width: calc(100% - 270px);
}
.sidebar ul li a{
color: white;
}
.sidebar ul li {
padding: 10px;
text-align: left;
margin-bottom: 10px; /* 增加底部间距 */
}
+3 -2
View File
@@ -9,11 +9,12 @@
</head>
<body>
<main>
<a href="{{ url_for('index')}}">return Homepage</a>
<h1>ABOUT US</h1>
<p>
@author yilv<br>
this website is based on flask
</p>
<footer><a href="{{ url_for('index')}}">return Homepage</a></footer>
</main>
<script src="{{ url_for('static', filename='js/script.js') }}"></script>
</body>
+8 -1
View File
@@ -4,7 +4,7 @@
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="{{ url_for('static', filename='style.css') }}">
<link rel="icon" href="{{ url_for('static', filename='icon.png') }}"> <!--添加图标-->
<link rel="icon" href="{{ url_for('static', filename='icon.png') }}"> <!--add the icon-->
<title>Dashboard</title>
</head>
@@ -25,6 +25,13 @@
<textarea id="content" name="content" required></textarea><br>
<button type="submit">Publish</button>
</form>
<footer>
<div class="footer-container">
<div class="footer-item"><a href="{{url_for('aboutus')}}"><strong>About Us</strong></a></div>
<div class="footer-item"><a href="https://flask.palletsprojects.com"><strong>About Flask</strong></a></div>
<div class="footer-item"><a href="http://www.scuec.edu.cn"><strong>About SCEUC</strong></a></div>
</div>
</footer>
</main>
</body>
</html>
+29 -13
View File
@@ -11,6 +11,7 @@
<header>
<nav>
<ul>
<!-- <li>yilv blog</li> -->
<li><a href="{{ url_for('signin') }}">Sign In</a></li>
<li><a href="{{ url_for('signup') }}">Sign Up</a></li>
<li><a href="{{ url_for('dashboard') }}">Dashboard</a></li>
@@ -21,20 +22,35 @@
</nav>
</header>
<main>
<h1>Welcome to Our Website</h1>
<div id="content-list">
{% for post in posts %}
<div class="content-item">
<strong>{{ post.username }}</strong>
<p>{{ post.content }}</p>
<small>Posted on: {{ post.created_at }}</small>
</div>
{% endfor %}
<div class="container">
<div class="sidebar">
<h2 style="text-align: center;">实用工具及教程</h2>
<ul>
<li><a href="{{ url_for('python') }}">python教程</a></li>
<li><a href="#">css实用工具</a></li>
<li><a href="#">文档在线工具</a></li>
<li><a href="{{ url_for('video') }}">科普视频</a></li>
</ul>
</div>
<div id="content-list">
{% for post in posts %}
<div class="content-item">
<strong>{{ post.username }}&nbsp;</strong>
<p>{{ post.content }}</p>
<small>Posted on: {{ post.created_at }}</small>
</div>
{% endfor %}
</div>
</div>
<footer>
<a href="{{url_for('aboutus')}}">about us</a>
</footer>
<footer>
<div class="footer-container">
<div class="footer-item"><a href="{{url_for('aboutus')}}"><strong>About Us</strong></a></div>
<div class="footer-item"><a href="https://flask.palletsprojects.com"><strong>About Flask</strong></a></div>
<div class="footer-item"><a href="http://www.scuec.edu.cn"><strong>About SCEUC</strong></a></div>
</div>
</footer>
</main>
<script src="{{ url_for('static', filename='js/script.js') }}"></script>
<script src="{{ url_for('static', filename='script.js') }}"></script>
</body>
</html>
+75
View File
@@ -0,0 +1,75 @@
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="{{ url_for('static', filename='python_css.css') }}">
<link rel="icon" href="{{ url_for('static', filename='icon.png') }}"> <!--添加图标-->
<title>Homepage</title>
</head>
<body>
<header>
<nav>
<ul>
<!-- <li>yilv blog</li> -->
<li><a href="{{ url_for('index') }}">HOMEpage</a></li>
<li><a href="{{ url_for('signin') }}">Sign In</a></li>
<li><a href="{{ url_for('signup') }}">Sign Up</a></li>
<li><a href="{{ url_for('dashboard') }}">Dashboard</a></li>
<!-- <li><a href="{{ url_for('commands') }}">commands</a></li> -->
{% if 'user' in session %}
<li><a href="{{ url_for('user') }}">User Profile</a></li>
{% endif %}
</ul>
</nav>
</header>
<main>
<div class="container">
<div class="sidebar">
<h2 style="text-align: center;">python教程</h2>
<ul>
<li><a href="#">python环境搭建</a></li>
<li><a href="#">python基本语法</a></li>
<li><a href="#">第一个python程序</a></li>
</ul>
</div>
<!-- 这里添加内容-->
<div id="content-list">
<div class="content-item">
<div>
<ul>
<li><h3>要在你的系统上搭建Python环境,你可以按照以下步骤操作。不同操作系统(Windows、macOS和Linux)可能略有不同。</h3></li>
<li><strong><i>1.安装Python</i></strong></li>
<li>(1)windows环境
访问<a href="www.python.org">Python官网</a>并下载最新版本的Python安装包(通常是Python 3.x版本)。<br>
运行下载的安装包,在安装选项中勾选“Add Python to PATH”。<br>
按照提示完成安装。<br></li>
<li>(2)linux环境<br>
大多数Linux发行版自带Python,但你可以通过包管理器安装最新版本。</li>
<li>ubuntu/debian:<br>
sudo apt update
sudo apt install python3 python3-pip
</li>
<li>fedora:<br>
sudo dnf install python3 python3-pip
</li>
<li>2.验证安装<br>
python -V或者python3 -V</li>
</ul>
</div>
</div>
</div>
</div>
<footer>
<div class="footer-container">
<div class="footer-item"><a href="{{url_for('aboutus')}}"><strong>About Us</strong></a></div>
<div class="footer-item"><a href="https://flask.palletsprojects.com"><strong>About Flask</strong></a></div>
<div class="footer-item"><a href="http://www.scuec.edu.cn"><strong>About SCEUC</strong></a></div>
</div>
</footer>
</main>
<script src="{{ url_for('static', filename='js/script.js') }}"></script>
</body>
</html>
+1 -1
View File
@@ -4,7 +4,7 @@
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="{{ url_for('static', filename='style.css') }}">
<link rel="icon" href="{{ url_for('static', filename='icon.png') }}"> <!--添加图标-->
<link rel="icon" href="{{ url_for('static', filename='icon.png') }}"> <!--add the icon -->
<title>Sign In</title>
</head>
<body>
+5 -5
View File
@@ -12,18 +12,18 @@
<h1 style="text-align: center;">Sign up</h1>
<!-- <div id="error-message" style="color: red;"></div> -->
<form action="/signup" method="post" id="signup-form">
<label for="username">用户名:</label>
<label for="username">username:</label>
<input type="text" id="username" name="username" required><br>
<label for="password">密码:</label>
<label for="password">password:</label>
<input type="password" id="password" name="password" required><br>
<label for="confirm-password">确认密码:</label>
<input type="password" id="confirm-password" name="confirm-password" required><br>
<label for="age">年龄:</label>
<label for="age">age:</label>
<input type="number" id="age" name="age" required><br>
<label for="captcha">验证码:</label>
<label for="captcha">captcha:</label>
<input type="text" id="captcha" name="captcha" required>
<img id="captcha-image" src="{{ url_for('captcha') }}" alt="Captcha"><br>
<button type="submit">注册</button>
<button type="submit">sign up</button>
</form>
<!-- <footer>
<a href="{{ url_for('') }}">index</a>
+7
View File
@@ -40,6 +40,13 @@
{% endfor %}
</div>
<a href="{{ url_for('logout') }}" class="logout-button">Logout</a>
<footer>
<div class="footer-container">
<div class="footer-item"><a href="{{url_for('aboutus')}}"><strong>About Us</strong></a></div>
<div class="footer-item"><a href="https://flask.palletsprojects.com"><strong>About Flask</strong></a></div>
<div class="footer-item"><a href="http://www.scuec.edu.cn"><strong>About SCEUC</strong></a></div>
</div>
</footer>
</main>
</body>
</html>
+87
View File
@@ -0,0 +1,87 @@
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Simple Video Player</title>
<link rel="stylesheet" href="{{ url_for('static', filename='style.css') }}">
<style>
body {
font-family: Arial, sans-serif;
display: flex;
flex-direction: column;
align-items: center;
margin-top: 50px;
}
#videoPlayer {
width: 600px;
height: 400px;
border: 1px solid #ccc;
}
.controls {
margin-top: 10px;
}
</style>
</head>
<body>
<header>
<nav>
<ul>
<li><a href="{{ url_for('signin') }}">Sign In</a></li>
<li><a href="{{ url_for('signup') }}">Sign Up</a></li>
<li><a href="{{ url_for('dashboard') }}">Dashboard</a></li>
{% if 'user' in session %}
<li><a href="{{ url_for('user') }}">User Profile</a></li>
{% endif %}
</ul>
</nav>
</header>
<main>
<div class="container">
<div class="sidebar">
<h2 style="text-align: center;">实用工具及教程</h2>
<ul>
<li><a href="{{ url_for('python') }}">python教程</a></li>
<li><a href="#">css实用工具</a></li>
<li><a href="#">文档在线工具</a></li>
<li><a href="{{ url_for('video') }}">科普视频</a></li>
</ul>
</div>
<div class="content">
<h1>Simple Video Player</h1>
<video id="videoPlayer" controls>
<source src="{{ url_for('static', filename='1.mp4') }}" type="video/mp4">
Your browser does not support the video tag.
</video>
<div class="controls">
<button title="Play video" onclick="playVideo()">Play</button>
<button title="Pause video" onclick="pauseVideo()">Pause</button>
<input type="range" id="volumeControl" min="0" max="1" step="0.1" value="1" title="Set volume" placeholder="Volume" onchange="setVolume(this.value)">
</div>
</div>
</div>
</main>
<footer>
<div class="footer-container">
<div class="footer-item"><a href="{{url_for('aboutus')}}"><strong>About Us</strong></a></div>
<div class="footer-item"><a href="https://flask.palletsprojects.com"><strong>About Flask</strong></a></div>
<div class="footer-item"><a href="http://www.scuec.edu.cn"><strong>About SCEUC</strong></a></div>
</div>
</footer>
<script>
const video = document.getElementById('videoPlayer');
function playVideo() {
video.play();
}
function pauseVideo() {
video.pause();
}
function setVolume(value) {
video.volume = value;
}
</script>
</body>
</html>