forked from jimdevops19/FlaskSeries
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Code after the sixth episode of Flask Series
- Loading branch information
1 parent
93ba5fa
commit ddaed50
Showing
11 changed files
with
139 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
from flask import Flask, render_template | ||
from flask_sqlalchemy import SQLAlchemy | ||
app = Flask(__name__) | ||
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///market.db' | ||
db = SQLAlchemy(app) | ||
|
||
from market import routes |
Binary file added
BIN
+389 Bytes
06 - Project Restructure/market/__pycache__/__init__.cpython-38.pyc
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
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,12 @@ | ||
from market import db | ||
|
||
|
||
class Item(db.Model): | ||
id = db.Column(db.Integer(), primary_key=True) | ||
name = db.Column(db.String(length=30), nullable=False, unique=True) | ||
price = db.Column(db.Integer(), nullable=False) | ||
barcode = db.Column(db.String(length=12), nullable=False, unique=True) | ||
description = db.Column(db.String(length=1024), nullable=False, unique=True) | ||
|
||
def __repr__(self): | ||
return f'Item {self.name}' |
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,13 @@ | ||
from market import app | ||
from flask import render_template | ||
from market.models import Item | ||
|
||
@app.route('/') | ||
@app.route('/home') | ||
def home_page(): | ||
return render_template('home.html') | ||
|
||
@app.route('/market') | ||
def market_page(): | ||
items = Item.query.all() | ||
return render_template('market.html', items=items) |
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,60 @@ | ||
<!doctype html> | ||
<html lang="en"> | ||
<head> | ||
<!-- Required meta tags --> | ||
<meta charset="utf-8"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no"> | ||
<!-- Bootstrap CSS --> | ||
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" integrity="sha384-TX8t27EcRE3e/ihU7zmQxVncDAy5uIKz4rEkgIXeMed4M0jlfIDPvg6uqKI2xXr2" crossorigin="anonymous"> | ||
<title> | ||
{% block title %} | ||
|
||
{% endblock %} | ||
</title> | ||
</head> | ||
<body> | ||
<nav class="navbar navbar-expand-md navbar-dark bg-dark"> | ||
<a class="navbar-brand" href="#">Flask Market</a> | ||
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarNav"> | ||
<span class="navbar-toggler-icon"></span> | ||
</button> | ||
<div class="collapse navbar-collapse" id="navbarNav"> | ||
<ul class="navbar-nav mr-auto"> | ||
<li class="nav-item active"> | ||
<a class="nav-link" href="{{ url_for('home_page') }}">Home <span class="sr-only">(current)</span></a> | ||
</li> | ||
<li class="nav-item"> | ||
<a class="nav-link" href="{{ url_for('market_page') }}">Market</a> | ||
</li> | ||
</ul> | ||
<ul class="navbar-nav"> | ||
<li class="nav-item"> | ||
<a class="nav-link" href="#">Login</a> | ||
</li> | ||
<li class="nav-item"> | ||
<a class="nav-link" href="#">Register</a> | ||
</li> | ||
</ul> | ||
</div> | ||
</nav> | ||
{% block content %} | ||
|
||
{% endblock %} | ||
<!-- Future Content here --> | ||
|
||
|
||
|
||
<!-- Optional JavaScript --> | ||
<!-- jQuery first, then Popper.js, then Bootstrap JS --> | ||
<script src='https://kit.fontawesome.com/a076d05399.js'></script> | ||
<script src="https://code.jquery.com/jquery-3.5.1.slim.min.js" integrity="sha384-DfXdz2htPH0lsSSs5nCTpuj/zy4C+OGpamoFVy38MVBnE+IbbVYUew+OrCXaRkfj" crossorigin="anonymous"></script> | ||
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/umd/popper.min.js" integrity="sha384-9/reFTGAW83EW2RDu2S0VKaIzap3H66lZH81PoYlFhbGU+6BZp6G7niu735Sk7lN" crossorigin="anonymous"></script> | ||
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js" integrity="sha384-B4gt1jrGC7Jh4AgTPSdUtOBvfO8shuf57BaghqFfPlYxofvL8/KUEfYiJOMMV+rV" crossorigin="anonymous"></script> | ||
</body> | ||
<style> | ||
body { | ||
background-color: #212121; | ||
color: white | ||
} | ||
</style> | ||
</html> |
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,8 @@ | ||
{% extends 'base.html' %} | ||
{% block title %} | ||
Home Page | ||
{% endblock %} | ||
|
||
{% block content %} | ||
This is our content for the Home Page | ||
{% endblock %} |
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,34 @@ | ||
{% extends 'base.html' %} | ||
{% block title %} | ||
Market Page | ||
{% endblock %} | ||
|
||
{% block content %} | ||
<table class="table table-hover table-dark"> | ||
<thead> | ||
<tr> | ||
<!-- Your Columns HERE --> | ||
<th scope="col">ID</th> | ||
<th scope="col">Name</th> | ||
<th scope="col">Barcode</th> | ||
<th scope="col">Price</th> | ||
<th scope="col">Options</th> | ||
</tr> | ||
</thead> | ||
<tbody> | ||
<!-- Your rows inside the table HERE: --> | ||
{% for item in items %} | ||
<tr> | ||
<td>{{ item.id }}</td> | ||
<td>{{ item.name }}</td> | ||
<td>{{ item.barcode }}</td> | ||
<td>{{ item.price }}$</td> | ||
<td> | ||
<button class="btn btn-outline btn-info">More Info</button> | ||
<button class="btn btn-outline btn-success">Purchase this Item</button> | ||
</td> | ||
</tr> | ||
{% endfor %} | ||
</tbody> | ||
</table> | ||
{% endblock %} |
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,5 @@ | ||
from market import app | ||
|
||
#Checks if the run.py file has executed directly and not imported | ||
if __name__ == '__main__': | ||
app.run(debug=True) |