Initial commit

This commit is contained in:
Nico Melone
2025-01-21 10:29:57 -06:00
commit 1222be277d
11 changed files with 131 additions and 0 deletions

BIN
.DS_Store vendored Normal file

Binary file not shown.

2
.gitattributes vendored Normal file
View File

@@ -0,0 +1,2 @@
# Auto detect text files and perform LF normalization
* text=auto

Binary file not shown.

36
app.py Normal file
View File

@@ -0,0 +1,36 @@
from flask import Flask, render_template, request, redirect, url_for
from models import db, Item
app = Flask(__name__)
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///items.db'
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
db.init_app(app)
@app.before_request
def initialize_app():
if not hasattr(app, 'is_initialized'):
db.create_all()
app.is_initialized = True
@app.route('/')
def home():
items = Item.query.all()
testList = [1,2,3,"Apple"]
username = "Test_Username"
return render_template('home.html', items=items, testList=testList, username=username)
@app.route('/add', methods=['GET', 'POST'])
def add_item():
if request.method == 'POST':
name = request.form['name']
description = request.form['description']
new_item = Item(name=name, description=description)
db.session.add(new_item)
db.session.commit()
return redirect(url_for('home'))
return render_template('add_item.html')
if __name__ == '__main__':
app.run(debug=True)

BIN
instance/items.db Normal file

Binary file not shown.

8
models.py Normal file
View File

@@ -0,0 +1,8 @@
from flask_sqlalchemy import SQLAlchemy
db = SQLAlchemy()
class Item(db.Model):
id = db.Column(db.Integer, primary_key=True)
name = db.Column(db.String(80), nullable=False)
description = db.Column(db.String(200), nullable=True)

3
requirements.txt Normal file
View File

@@ -0,0 +1,3 @@
Flask==2.3.3
Flask-SQLAlchemy==3.0.5
Werkzeug==2.3.7

22
static/css/styles.css Normal file
View File

@@ -0,0 +1,22 @@
body {
font-family: Arial, sans-serif;
margin: 0;
padding: 0;
}
header {
background-color: #007BFF;
color: white;
padding: 1em 0;
text-align: center;
}
nav a {
color: white;
margin: 0 15px;
text-decoration: none;
}
main {
padding: 20px;
}

14
templates/add_item.html Normal file
View File

@@ -0,0 +1,14 @@
{% extends "base.html" %}
{% block content %}
<h1>Add a New Item</h1>
<form method="post">
<label for="name">Name:</label>
<input type="text" id="name" name="name" required>
<br>
<label for="description">Description:</label>
<textarea id="description" name="description"></textarea>
<br>
<button type="submit">Add Item</button>
</form>
{% endblock %}

21
templates/base.html Normal file
View File

@@ -0,0 +1,21 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Flask App</title>
<link rel="stylesheet" href="{{ url_for('static', filename='css/styles.css') }}">
</head>
<body>
<header>
<nav>
<a href="{{ url_for('home') }}">Home</a>
<a href="{{ url_for('add_item') }}">Add Item</a>
</nav>
</header>
<main>
{% block content %}{% endblock %}
{% block moreContent%}Placeholder{% endblock %}
</main>
</body>
</html>

25
templates/home.html Normal file
View File

@@ -0,0 +1,25 @@
{% extends "base.html" %}
{% block content %}
{# If there is username display it otherwise stay generic #}
{% if username %}
<h1>Item List for {{username}}</h1>
{% else %}
<h1>Item List</h1>
{% endif %}
<ul>
{% for item in items %}
<li><strong>{{ item.name }}</strong>: {{ item.description }}</li>
{% endfor %}
</ul>
<ul>
{% for thing in testList %}
<li>{{ thing }}</li>
{% endfor %}
</ul>
{% endblock %}
{% block moreContent%}
<h2>This is a test for more content</h2>
{% endblock %}