-
-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Decisions need to be made on the database and how the server will be hosted befor a database can be created. Preferably a linux computer, because it is better for MySQL. Additionally, we could find an online database, but it will probably cost money, so I would not recommend.
- Loading branch information
Showing
3 changed files
with
59 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
from flask import Flask | ||
from flask_mysqldb import MySQL | ||
|
||
# requires a hosting site for database | ||
|
||
app = Flask(__name__) | ||
|
||
# configure database | ||
# probably should use extern variables for this infomation | ||
# documentation https://flask-mysqldb.readthedocs.io/en/latest/ | ||
app.config['MYSQL_HOST'] = '' | ||
app.config['MYSQL_USER'] = '' | ||
app.config['MYSQL_PASSWORD'] = '' | ||
app.config['MYSQL_DB'] = '' | ||
|
||
# instanization of mysql object | ||
mysql = MySQL(app) | ||
|
||
@app.route('/') | ||
# sample section where infomation if placed into database | ||
def home(): | ||
# create cursor object | ||
# allows us to execute querries | ||
cursor = mysql.connection.cursor() | ||
# insert info into the user model | ||
cursor.execute("INSERT INTO user(name,email) VALUES(%s,%s)", (name,email)) | ||
# saves the changes | ||
mysql.conntection.commit() | ||
cursor.close() | ||
return 'Flask' | ||
|
||
@app.route('/users') | ||
# sample code how infomation is retrieved from database | ||
def users(): | ||
cursor = mysql.connection.cursor() | ||
# returns the number of rows in user model in database | ||
resultValue = cur.execute("SELECT * FROM users") | ||
if resultValue > 0: # e.g. there is something inside of the database | ||
# returns all of rows which has been fetched by the cursor | ||
userDetails = cursor.fetchall() | ||
for user in userDetails: | ||
print(user[0]) # username | ||
print(user[0]) # user email | ||
|
||
if __name__ == "__main__": | ||
app.run() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters