mirror of
https://github.com/ProgramSnail/python_web_proj_2021.git
synced 2025-12-06 02:48:41 +00:00
prototype of ui, db connection
This commit is contained in:
parent
f5beb70c3d
commit
68a3b3ca1e
6 changed files with 122 additions and 22 deletions
31
app.py
31
app.py
|
|
@ -1,7 +1,30 @@
|
|||
from flask import Flask, render_template
|
||||
import os
|
||||
from flask import Flask, render_template, request, redirect, url_for, session
|
||||
from flask_sqlalchemy import SQLAlchemy
|
||||
|
||||
app = Flask("App")
|
||||
app.config["SQLALCHEMY_DATABASE_URI"] = "sqlite:////" + \
|
||||
os.path.join(os.path.abspath(os.path.dirname(__file__)), "app.db")
|
||||
app.config["SQLALCHEMY_TRACK_MODIFICATIONS"] = False
|
||||
app.secret_key = "SAFmdsdDkSukyuDd"
|
||||
db = SQLAlchemy(app)
|
||||
|
||||
@app.route("/")
|
||||
def index():
|
||||
return render_template("index.html")
|
||||
@app.route("/", methods=["POST", "GET"])
|
||||
def login():
|
||||
if request.method == "POST":
|
||||
name = request.form["name"]
|
||||
password = request.form["password"]
|
||||
session["user_name"] = name
|
||||
session["user_password"] = password
|
||||
return redirect(url_for("user_page", user_name=name))
|
||||
else:
|
||||
if "user_name" in session:
|
||||
return redirect(url_for("user_page", user_name=session["user_name"]))
|
||||
return render_template("login.html")
|
||||
|
||||
|
||||
@app.route("/<user_name>")
|
||||
def user_page(user_name):
|
||||
if not "user_name" in session:
|
||||
return redirect(url_for("login"))
|
||||
return render_template("user_page.html")
|
||||
2
requirements
Normal file
2
requirements
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
flask
|
||||
flask-sqlalchemy
|
||||
BIN
static/images/default_avatar.png
Normal file
BIN
static/images/default_avatar.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 8 KiB |
33
templates/login.html
Normal file
33
templates/login.html
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>Language Learner</title>
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<link rel="stylesheet" href="/static/w3.css">
|
||||
<link rel="stylesheet" href="/static/fontawesome/css/all.css">
|
||||
</head>
|
||||
<body>
|
||||
<header class="w3-container w3-dark-gray">
|
||||
<h1><i class="fas fa-dice-d20"></i> Language Learner</h1>
|
||||
</header>
|
||||
<div class="w3-container w3-margin">
|
||||
<div class="w3-container w3-third"></div>
|
||||
<div class="w3-panel w3-card w3-third">
|
||||
<form method="POST" action="" class="w3-container w3-margin w3-center">
|
||||
<h2>Log in / Sign up</h2>
|
||||
<label>Name</label>
|
||||
<input class="w3-input w3-section" type="text"
|
||||
name="name" placeholder="Enter Name" required="">
|
||||
<label>Password</label>
|
||||
<input class="w3-input w3-section" type="password"
|
||||
name="password" placeholder="Enter Password" required="">
|
||||
<input class="w3-button w3-green w3-section" type="submit" value="Submit">
|
||||
</form>
|
||||
</div>
|
||||
<div class="w3-container w3-third"></div>
|
||||
</div>
|
||||
<footer class="w3-container w3-light-gray">
|
||||
<label class="w3-center">My app.</label>
|
||||
</footer>
|
||||
</body>
|
||||
</html>
|
||||
|
|
@ -1,18 +0,0 @@
|
|||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>App</title>
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<link rel="stylesheet" href="/static/w3.css">
|
||||
<link rel="stylesheet" href="/static/fontawesome/css/all.css">
|
||||
</head>
|
||||
<body>
|
||||
<header class="w3-container">
|
||||
|
||||
</header>
|
||||
|
||||
<footer class="w3-container">
|
||||
|
||||
</footer>
|
||||
</body>
|
||||
</html>
|
||||
60
templates/user_page.html
Normal file
60
templates/user_page.html
Normal file
|
|
@ -0,0 +1,60 @@
|
|||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>Language Learner</title>
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<link rel="stylesheet" href="/static/w3.css">
|
||||
<link rel="stylesheet" href="/static/fontawesome/css/all.css">
|
||||
</head>
|
||||
<body>
|
||||
<header class="w3-container w3-dark-gray">
|
||||
<h1><i class="fas fa-dice-d20"></i> Language Learner</h1>
|
||||
</header>
|
||||
<div class="w3-container w3-margin">
|
||||
<div class="w3-panel w3-card w3-third w3-margin">
|
||||
<img src="/static/images/default_avatar.png" class="w3-circle w3-margin" style="width: 60%" alt="avatar">
|
||||
<h1>User Name</h1>
|
||||
<b>Interests:</b>
|
||||
<ul class="w3-ul">
|
||||
<li>Football</li>
|
||||
<li>Programming</li>
|
||||
<li>Something</li>
|
||||
</ul>
|
||||
</div>
|
||||
<div class="w3-card w3-panel w3-margin w3-third w3-padding-large">
|
||||
<form method="POST" action="" style="width: 100%"
|
||||
class="w3-card w3-section w3-padding-small w3-center">
|
||||
<input type="text" name="interest" plaseholder="Your interest">
|
||||
<input class="w3-button w3-ripple w3-green" type="submit" value="Submit">
|
||||
</form>
|
||||
<ul class="w3-ul w3-border" style="width: 100%">
|
||||
<li>
|
||||
<label>Interest 1</label>
|
||||
</li>
|
||||
<li>
|
||||
<label>Interest 2</label>
|
||||
</li>
|
||||
<li>
|
||||
<label>Interest 3</label>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
<div class="w3-panel w3-margin w3-third">
|
||||
<ul class="w3-ul w3-card" style="width: 100%">
|
||||
<li>
|
||||
<label>User 1</label>
|
||||
</li>
|
||||
<li>
|
||||
<label>User 2</label>
|
||||
</li>
|
||||
<li>
|
||||
<label>User 3</label>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
<footer class="w3-container w3-light-gray">
|
||||
<label class="w3-center">My app.</label>
|
||||
</footer>
|
||||
</body>
|
||||
</html>
|
||||
Loading…
Add table
Add a link
Reference in a new issue