-
Notifications
You must be signed in to change notification settings - Fork 1
/
app.py
117 lines (95 loc) · 3.42 KB
/
app.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
from flask import Flask,render_template,request,redirect
from flask_sqlalchemy import SQLAlchemy
from datetime import datetime
import json
from flask_mail import Mail
from flask_migrate import Migrate
with open('config.json' , 'r') as c:
paras=json.load(c)["para"]
app = Flask(__name__)
app.config.update(
MAIL_SERVER='smtp.gmail.com',
MAIL_PORT='465',
MAIL_USE_SSL=True,
MAIL_USERNAME=paras['gmail_id'],
MAIL_PASSWORD=paras['gmail_pass']
)
mail=Mail(app)
app.config['SQLALCHEMY_DATABASE_URI'] = paras['local_uri']
db = SQLAlchemy(app)
migrate = Migrate(app, db)
class Details(db.Model):
sno = db.Column(db.Integer, primary_key=True)
Name = db.Column(db.String(80), nullable=False)
Email = db.Column(db.String(120), unique=True, nullable=False)
Phone = db.Column(db.String(120), unique=True, nullable=False)
def __repr__(self):
return '<User %r>' % self.Name
class Blogs(db.Model):
sno = db.Column(db.Integer, primary_key=True)
Topic = db.Column(db.String(80), nullable=False)
Name = db.Column(db.String(120), unique=True, nullable=False)
slug=db.Column(db.String(25),unique=True)
Content = db.Column(db.String(1200), unique=True, nullable=False)
Date = db.Column(db.DateTime, default=datetime.utcnow)
def __repr__(self):
return '<User %r>' % self.Name
@app.route("/")
def hello_world():
blog=Blogs.query.all()
return render_template("front.html",blog=blog)
@app.route("/logout")
def logout():
return redirect("/admin")
@app.route("/delete/<string:sno>" , methods=['GET','POST'])
def delete(sno):
dets=Details.query.filter_by(sno=sno).first()
db.session.delete(dets)
db.session.commit()
return redirect("/admin")
@app.route("/admin",methods=['GET','POST'])
def admin():
if request.method=='POST':
user=request.form.get('user')
password=request.form.get('pass')
if user==paras['id'] and password==paras['pass']:
dets=Details.query.all()
return render_template("info.html",dets=dets)
else:
return render_template("admin.html")
return render_template("admin.html")
@app.route('/front' , methods=['GET'])
def mainscreen():
blog=Blogs.query.all()
return render_template('front.html', blog=blog)
@app.route('/contact', methods=['GET','POST'])
def contact():
if(request.method=='POST'):
name=request.form.get('name')
email=request.form.get('email')
phone=request.form.get('phone')
entry=Details(Name=name,Email=email,Phone=phone)
db.session.add(entry)
db.session.commit()
mail.send_message('This message is from ' + name,
sender=email, recipients=[paras['gmail_id']],
body="\ncontact number" + phone
)
return render_template('contact.html')
@app.route("/blog/<string:Slugs>",methods=['GET'])
def blog(Slugs):
blog=Blogs.query.filter_by(slug = Slugs ).first()
return render_template('blog.html',blog=blog)
@app.route("/addcontent" , methods=['GET','POST'])
def addcontent():
if request.method=='POST':
topic=request.form.get('topic')
author=request.form.get('author')
slug=request.form.get('slug')
blog=request.form.get('blog')
quest=Blogs(Topic=topic,Name=author,Content=blog,slug=slug)
db.session.add(quest)
db.session.commit()
return render_template('addcontent.html')
if __name__=="__main__":
app.run(debug=True)