Мне нужна помощь, пожалуйста. Я просто не могу получить этот код для вставки данных из формы HTML в MySQL. Строки всегда вставляются без каких-либо данных. Совершенно пусто Дайте мне знать ваши мысли!
PS: MySql имеет еще 2 поля, которые я пока не использую, и все эти файлы размещены на PythonAnywhere.
HTML (только форма):
<form action="{{ url_for('register_user') }}" method="post">
<div class="register-form">
<input type="text" class="register-field" id="firstname" value="" placeholder="First name" name="firstname">
<label class="register-field-icon fui-user" for="register-name"></label>
<input type="text" class="register-field" id="lastname" value="" placeholder="Last name" name="lastname">
<label class="register-field-icon fui-user" for="register-name"></label>
<input type="text" class="register-field" id="email" value="" placeholder="Email" name="email">
<label class="register-field-icon fui-user" for="register-name"></label>
<input type="password" class="register-field" id="password" value="" placeholder="Password" name="password">
<label class="register-field-icon fui-lock" for="register-pass"></label>
<label class="register-field-icon fui-lock" for="register-pass"></label>
<input type="submit" value="Register" id="register-btn" class="btn register-btn">
</div>
</form>
FLASK (без сведений о соединении для MySql):
from datetime import datetime
from flask import Flask, redirect, render_template, request, url_for, session
from flask_login import current_user, login_required, login_user, LoginManager, logout_user, UserMixin
from flask_migrate import Migrate
from flask_sqlalchemy import SQLAlchemy
from werkzeug.security import check_password_hash
from flask import session as login_session
@app.route("/register/", methods=["GET", "POST"])
def register_user():
if request.method == "GET":
return render_template("register.html")
else:
User_Data = Reg_User(firstname=request.form["firstname"],lastname=request.form["lastname"],email=request.form["email"],password_hash=request.form["password"])#,groups="freeuser")
db.session.add(User_Data)
db.session.commit()
return redirect(url_for('login'))
class Reg_User(db.Model):
__tablename__ = 'users'
def __init__(self, firstname, lastname, email, password_hash):#, groups):
id = db.Column(db.Integer, primary_key=True)
firstname = db.Column(db.String(20), unique=False, nullable=False)
lastname = db.Column(db.String(45), unique=False, nullable=False)
email = db.Column(db.String(45), unique=True, nullable=False)
password_hash = db.Column(db.String(128), unique=False, nullable=False)
def __repr__(self):
return '<Reg_User %r>'.format(self.username)
MYSQL:
+--------------------------------------------------------------------------
| id | username | password_hash | firstname | lastname | email | groups | regtime |
+--------------------------------------------------------------------------
| 43 | NULL | NULL | NULL | NULL | NULL | NULL | 2019-01-09 22:00:56 |
| 44 | NULL | NULL | NULL | NULL | NULL | NULL | 2019-01-09 22:55:09 |
| 45 | NULL | NULL | NULL | NULL | NULL | NULL | 2019-01-09 23:04:15 |
| 46 | NULL | NULL | NULL | NULL | NULL | NULL | 2019-01-09 23:10:32 |