from flask import Flask,render_template,url_for,redirect,session,request,flash,logging from flask_mysqldb import MySQL from wtforms import Form,StringField,TextAreaField,PasswordField,validators app = Flask(__name__) app.config["MYSQL_HOST"] = "localhost" app.config["MYSQL_USER"] = "root" app.config["MYSQL_PASSWORD"] = "" app.config["MYSQL_DB"] = "ikblog" app.config["MYSQL_CURSORCLASS"] = "DictCursor" mysql = MySQL(app) #Kayıt Formu class RegisterForm(Form): name = StringField("İsim Soyisim:", validators=[validators.length(min = 3, max = 20)]) username = StringField("Kullanıcı Adı", validators=[validators.length(min = 5, max = 30)]) password = PasswordField("Parola",validators=[validators.DataRequired(),validators.EqualTo(fieldname = "confirm_password",message="Parolalarınız uyuşmuyor")]) confirm_password = PasswordField("Parola Doğrulama:") email = StringField("E-mail Adresi:",validators=[validators.Email("Lütfen geçerli bir E-mail adresi giriniz.")]) #Ana ekran @app.route("/") def index(): return render_template("index.html") #Hakkımda sayfası @app.route("/about") def about(): return render_template("about.html") #İletişim sayfası @app.route("/contact") def contact(): return render_template("contact.html") #Giriş sayfası @app.route("/login") def login(): return render_template("login.html") #Kayıt sayfası @app.route("/register",methods = ["GET","POST"]) def register(): form = RegisterForm(request.form) if request == "POST": name = form.name.data username = form.username.data password = form.password.data email = form.email.data cursor = mysql.connection.cursor() sorgu = "Insert into users(name,username,password,email) VALUES(%s,%s,%s,%s)" cursor.execute(sorgu,(name,username,password,email)) mysql.connection.commit() cursor.close() return redirect(url_for("index")) else: return render_template("register.html", form = form) #Makale sayfası @app.route("/articles") def articles(): return render_template("articles.html") #Referans sayfası @app.route("/references") def references(): return render_template("references.html") #İnsan Kaynakları sayfası @app.route("/ikpage") def ikpage(): return render_template("ikpage.html") if __name__ == "__main__": app.run(debug=True)