Advertisement
Guest User

Untitled

a guest
Jan 29th, 2020
199
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.04 KB | None | 0 0
  1. #share data
  2. #endpoint - точки входа
  3. #flask, django, aiohttp
  4. #pip install flask
  5. #python -m pip install flask
  6. from flask import Flask, render_template, request
  7. from db import add_user
  8. from sqlalchemy.exc import IntegrityError
  9. app = Flask(__name__)
  10. # app=decorator
  11. @app.route('/', methods=['GET', 'POST'])
  12. def index():
  13. if request.method == 'GET':
  14. return render_template('index.html')
  15. else:
  16. email = request.form['email']
  17. username = request.form['username']
  18. password = request.form['pw']
  19. password_check = request.form['pw2']
  20. if password != password_check:
  21. return render_template('index.html', error='password_error')
  22. try:
  23. add_user(username, email, password)
  24. except IntegrityError:
  25. return render_template('index.html', error='already_exists')
  26. return 'User was successfully signed up'
  27.  
  28. @app.route('/<name>')
  29. def hello_ivana(name):
  30. return render_template('index_ivana.html', name=name)
  31.  
  32. app.run(debug=True)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement