Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from flask import Flask, render_template, request, redirect, url_for
- from flask_sqlalchemy import SQLAlchemy
- from datetime import datetime
- application = Flask(__name__)
- application.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///users.db'
- application.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
- db = SQLAlchemy(application)
- class Users(db.Model):
- id = db.Column(db.Integer, primary_key=True)
- username = db.Column(db.String(32), primary_key=True, nullable=False)
- email = db.Column(db.String(64), primary_key=True, nullable=False)
- pword = db.Column(db.String(32), nullable=False)
- date = db.Column(db.DateTime, default=datetime.utcnow)
- def __repr__(self):
- return '<Users %r' % self.id
- @application.route('/')
- @application.route('/index.html')
- def hello():
- return render_template("index.html")
- @application.route('/about/')
- @application.route('/about/index.html')
- def about():
- return render_template("about/index.html")
- @application.route('/login', methods=["GET", "POST"])
- @application.route('/login/index.html', methods=["GET", "POST"])
- def login():
- if request.method == "GET":
- return render_template("login/index.html")
- else:
- username = request.form['username']
- email = request.form['email']
- pword = request.form['pword']
- user = Users(username=username, email=email, pword=pword)
- try:
- db.session.add(user)
- db.session.commit()
- return "Вы успешно зарегистрировались"
- except:
- return "При регистрации произошла ошибка"
- if __name__ == "__main__":
- application.run(debug=True)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement