from flask import Flask, render_template, url_for, request, redirect
from flask_sqlalchemy import SQLAlchemy
from datetime import datetime
app = Flask(
name)
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///blog.db'
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
db = SQLAlchemy(app)
class Article(db.Model):
id = db.Column(db.Integer, primary_key=True)
intro = db.Column(db.String(300), nullable=False)
title = db.Column(db.String(100), nullable=False)
text = db.Column(db.Text(100), nullable=False)
date = db.Column(db.DateTime, default=datetime.utcnow)
def
repr(self):
return '<Article %r>' %
self.iddb.create_all()
db.session.commit()
@app.route('/')
@app.route('/home')
def index():
return render_template("index.html")
@app.route('/about')
def about():
return render_template("about.html")
@app.route('/contact')
def contact():
return render_template("contact.html")
@app.route('/create-article', methods=['POST', 'GET'])
def create_articlet():
if request.method == "POST":
title = request.form['title']
intro = request.form['intro']
text = request.form['text']
article = Article(title=title, intro=intro, text=text)
try:
db.session.add(article)
db.session.commit()
return redirect('/')
except:
return "Error"
else:
return render_template("create-article.html")
if
name == "
main":
app.run(debug=True)