Matt
Matt

Reputation: 2350

Why am I getting a 500 error with this code?

I am trying to create a site with a webform using Flask, but I keep getting a 500 error

Here is my template/main.html

<DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <title>Sample Page</title>
    <meta name="viewport" content="width=device-width"
    initial=scale=1/>
    <link href="{{ url_for('static', filename='css/bootstrap.min.css') }}" rel="stylesheet">
    <link href="{{ url_for('static', filename='favicon.ico') }}" rel="shortcut icon">
</head>
<h2>Hello, this site is meant to test my fill_web_form.py script</h2>
<br>
<br>
<h1>Test Form</h1>
<form action="/" method="post" name="login">
      {{ render_field(form.test_form) }}<br>
      <p><input type="submit" value="Sign In"></p>
 </form>
</html>

Here is my init.py file

from flask import Flask, render_template
#import sqlite3

app = Flask(__name__)

@app.route('/')
def homepage():
    return render_template("main.html")



if __name__ == "__main__":
    app.run()

Here is my form.py file

from flask.ext.wtf import Form
from wtforms import StringField, BooleanField
from wtforms.validators import DataRequired

class LoginForm(Form):
    test_form = StringField('test_form', validators=[DataRequired()])

Why do I keep getting a 500 error? I cant figure it out.

Upvotes: 0

Views: 96

Answers (1)

furas
furas

Reputation: 142992

Run in debug mode app.run(debug=True) to see more information in browser.

You should import form and send to template. You may need secret_key to use csrf. etc.

from form import LoginForm

app.secret_key = 'A0Zr98j/3yX R~XHH!jmN]LWX/,?RT'

@app.route('/')
def homepage():
    return render_template("main.html", form=LoginForm())

Upvotes: 2

Related Questions