0

I'm working on a simple flask web application. I've uploaded everything in order to execute the project on my webserver. Unfortunately it won't work (Error: Internal Server Error The server encountered an internal error and was unable to complete your request. Either the server is overloaded or there is an error in the application.) I've yet found anything that could help me.

This is my code

from flask import Flask, render_template, url_for, request,\
    redirect, g
from wtforms import Form, StringField, PasswordField, validators
import mysql.connector 
from werkzeug.security import generate_password_hash
from db.db_credentials import DB_HOST, DB_USER, DB_PASSWORD, DB_DATABASE  

class RegistrationForm(Form):
    username = StringField('Nutzernamen angeben', [validators.Length(min=4, max=50)])
    email = StringField('Email angeben', [validators.Length(min=6, max=255)])
    password = PasswordField('Password angeben',
            [validators.length(min=4, max=256), validators.DataRequired(), validators.EqualTo('confirmation', message='Passwörter müssen übereinstimmen')])
    confirmation = PasswordField('Passwort wiederholen')


app = Flask(__name__)

@app.route('/')
@app.route('/index')
def index():
    return render_template('index.html')


@app.route('/registration', methods=["GET", "POST"])
def register(): 
    form = RegistrationForm(request.form)
    username = form.username.data
    password = form.password.data
    email = form.email.data

    password = generate_password_hash(password)
    if request.method == "POST" and form.validate():
        assert isinstance(DB_DATABASE, tuple)
        g.con = mysql.connector.connect(host=DB_HOST, user=DB_USER, password=DB_PASSWORD,
                                        database=DB_DATABASE)
        cursor = g.con.cursor
        cursor.execute("INSERT INTO konten (username, password, email) VALUES {%s}, {%s}, {%s} ",
                       username, password, email)
        return redirect(url_for("login"))
    return render_template("register.html", form=form)

if __name__ == '__main__':
    app.run(debug=True)

2
  • Include full stack trace in your post. Commented Jun 14, 2020 at 10:12
  • Check the logs of the webserver. Commented Jun 14, 2020 at 11:01

1 Answer 1

1
@app.route('/')
def myfun():
  return render_template('index.html')
@app.route('/index')
def index():
   return render_template('registration.html')

1.first you have to return a template.

2.My advice is to use sqlalchemy it will be very easy to sort the errors while connecting to database.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.