[Flask] Aggregate your news and vote for the content you care about.
1
"""
2
routes. module
3
----------------
4
5
This Python module contains the logic supporting:
6
1. between website pages
7
2. user requests to the server
8
3. requested content back to the user
9
10
Python dependencies:
11
- flask: provides web application features
12
- forms: provides secure user form submission
13
- sqlalchemy: provides communication with database on server.
14
15
Personal imports:
16
These are used to avoid cluttering this file with
17
placeholder data for posts' content.
18
"""
19
20
from datetime import datetime
21
from flask import Flask, render_template, flash, redirect, url_for
22
from forms import RegistrationForm, LoginForm
23
from flask_sqlalchemy import SQLAlchemy
24
25
from placeholder_posts import posts
26
from placeholder_news import news
27
from placeholder_messages import conversations
28
29
app = (__name__)
30
app.['SECRET_KEY'] = 'Scooby_Lu,_where_are_you?'
31
app.['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///site.db'
32
db = ()
33
34
35
class (.):
36
id = db.(.,primary_key=True)
37
username = db.(.(20),unique=True,nullable=False)
38
email = db.(.(120),unique=True,nullable=False)
39
image_file = db.(.(20),
40
nullable=False,
41
default='default.png')
42
password = db.(.(60),nullable=False)
43
posts = db.('Post',backref='author',lazy=True)
44
45
def __repr__(self):
46
return f"Alias('{self.}','{self.}','{self.}' )"
47
48
49
class (.):
50
id = db.(.,primary_key=True)
51
title = db.(.(100),nullable=False)
52
date_posted = db.(.,
53
nullable=False,
54
default=.)
55
content = db.(.,nullable=False)
56
user_id = db.(.,.('alias.id'),nullable=False)
57
58
def __repr__(self):
59
return f"Post('{self.}', '{self.}')"
60
61
62
@app.("/")
63
@app.("/home")
64
def ():
65
"""This is our homepage."""
66
home_posts = posts + news + conversations
67
return ('home.html',posts=)
68
69
70
@app.("/yes")
71
def ():
72
"""Another page, presenting the user with content marked as 'yes'."""
73
return ("yes.html",conversations=,news=)
74
75
76
@app.("/no")
77
def ():
78
"""This page contains an archive of 'no's, for forgiving user mistakes."""
79
archives = posts + news + messages
80
return ("no.html",archive=)
81
82
83
@app.("/register",methods=['GET','POST'])
84
def ():
85
"""Account registration page leveraging the form Python package."""
86
form = ()
87
if form.():
88
(f"Alias created for {..}.",'success')
89
return (('home'))
90
return ('register.html',title="Register",form=)
91
92
93
@app.("/login")
94
def ():
95
form = ()
96
return ('login.html',title="Login",form=)
97
98
99
# If this file is executed as a script (i.e. double-clicked),
100
# the Python interpreter will run the Flask process and begin serving
101
# the web pages on the standard localhost address (127.0.0.1).
102
# But if this file is called as a module by another Python script, it will not
103
# serve content to the web pages, but the function definitions contained in
104
# this file will be available to the calling script.
105
# E.g. calling script will know what the yes() function is.
106
if __name__ == '__main__':
107
app.(debug=True)
108