Skip to content
Snippets Groups Projects
Commit c3c33a7c authored by shivupoojar's avatar shivupoojar
Browse files

Added files

parent 8aab571e
No related branches found
No related tags found
No related merge requests found
app.py 0 → 100644
from flask import Flask, render_template, request, redirect
from flask_sqlalchemy import SQLAlchemy
import datetime
import os
app = Flask(__name__)
app.config['SQLALCHEMY_DATABASE_URI'] = os.environ['DATABASE_URL']
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
db = SQLAlchemy(app)
class Messageboard(db.Model):
__tablename__ = 'messages'
id = db.Column(db.Integer, primary_key=True)
message_text = db.Column(db.Text())
timestamp = db.Column(db.DateTime)
def __init__(self, message_text, timestamp):
self.message_text = message_text
self.timestamp = timestamp
db.create_all()
db.session.commit()
@app.route("/")
def home():
new_message = request.args.get('msg')
if new_message:
timestamp = datetime.datetime.now()
data = Messageboard(new_message,timestamp)
db.session.add(data)
db.session.commit()
messages = Messageboard.query.all()
return render_template('home.html', messages=messages)
\ No newline at end of file
# this file defines the pip packages neede by this application
flask==2.0.2
Flask-SQLAlchemy==2.5.1
Jinja2
psycopg2-binary
SQLAlchemy==1.3.23
<!doctype html>
<!-- This is a Jinja based template. To read more about Jinja, check
https://jinja.palletsprojects.com/en/3.0.x/ -->
<title>Message board</title>
<body>
<h4>There are {{ results |length }} messages on the board.</h4>
<h4> Here are the list of messages:</h4>
<ul>
{% for m in messages %}
<li>
"{{m.message_text}}" <small>Posted on {{m.timestamp}}</small>
</li>
{% endfor %}
</ul>
<h4> Enter a new message</h4>
<form action="/">
<label >Your message:</label><br>
<input type="text" name="msg"><br>
<input type="submit" value="Submit">
</form>
</body>
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment