Untitled
unknown
python
a year ago
1.9 kB
8
Indexable
from flask import Flask, render_template, request, redirect, url_for
from flask_sqlalchemy import SQLAlchemy
import os
app = Flask(__name__)
@app.route('/')
def home():
return render_template('index.html')
@app.route('/about')
def about():
return render_template('about.html')
@app.route('/inventory')
def inventory():
return render_template('inventory.html')
@app.route('/contact')
def contact():
return render_template('contact.html')
basedir = os.path.abspath(os.path.dirname(__file__))
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///' + os.path.join(basedir, 'gwc_inquiries.db')
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
db = SQLAlchemy(app)
# define model/table schema)
class Inquiry(db.Model):
id = db.Column(db.Integer, primary_key=True, autoincrement=True)
name = db.Column(db.String(100), nullable=False)
email = db.Column(db.String(120), nullable=False)
message = db.Column(db.Text, nullable=False)
def __init__(self, name, email, message):
self.name = name
self.email = email
self.message = message
# Route for the inquiry form
@app.route('/inquiry', methods=['GET', 'POST'])
def inquiry():
if request.method == 'POST':
name = request.form['name']
email = request.form['email']
# phone = request.form['phone']
message = request.form['message']
# Create a new inquiry instance
new_inquiry = Inquiry(name=name, email=email, message=message)
# Add and commit to the database
db.session.add(new_inquiry)
db.session.commit()
return redirect(url_for('thank_you'))
return render_template('inquiry.html')
@app.route('/thank-you')
def thank_you():
return '<h1>Thank you for your inquiry!</h1>'
with app.app_context():
db.create_all()
if __name__ == '__main__':
app.run(debug=True)
Editor is loading...
Leave a Comment