My submit button doesn't work form name.html I don't know where is the problem I check it from my .py file but still have this problem actually wanted me to define submite but where and how ? Is there problem with my name.html? or it's about formername class?
from flask import Flask , render_template,url_for
from flask_wtf import FlaskForm
from wtforms import StringField,SubmitField
from wtforms.validators import DataRequired
#flask instance
app = Flask (__name__)
app.config['SECRET_KEY'] = "my super secret key that no one is supposed ti know!"
# ----------------------------------------------------
#create a form class
class NamerForm(FlaskForm):
name = StringField ("What's Your Name?",validators=[DataRequired()])
Submit = SubmitField('Submit')
# ----------------------------------------------------
#create route decorator
@app.route('/')
# def index ():
# return "<h1>Hello World!</h1>"
#Filter!!!
# safe = will do everything between tags + changes
# capitalize
# lower
# upper
# tittle = first letter of all words capitalized
# trim = remove spaces from the end
# Striptags = will remove everything between tags = no change will happen
# --------------------------------------------------
def index ():
first_name = 'Maryam'
stuff = "This is Bold Text"
favorite_pizza = ["Pepperoni" , "Cheese" ,"Mushrooms" , 12 ]
return render_template('index.html' ,
first_name = first_name ,
stuff = stuff ,
favorite_pizza = favorite_pizza )
# --------------------------------------------------
#localhost:5000/user/Maryam or whatever name :)
# @app.route('/user/<name>')
# def user (name):
# return "<h1>Hello , {} !!!</h1>".format(name)
# --------------------------------------------------
#user_name it's a jinja tag!
@app.route('/user/<name>')
def user (name):
return render_template('user.html' , user_name=name)
# --------------------------------------------------
#create custom Error pages
#Invalid URL
@app.errorhandler(404)
def page_not_found(e):
return render_template('404.html') ,404
# --------------------------------------------------
#Internal Server Error
@app.errorhandler(500)
def page_not_found(e):
return render_template('500.html') ,500
#---------------------------------------------------
#create name page
@app.route('/name' , methods=['GET','POST'])
def name():
name = None
form = NamerForm()
#validate form
if form.validate_on_submit():
name = form.name.data
form.name.data = ''
return render_template('name.html',
name = name,
form = form)
#---------------------------------------------------
if __name__ == '__main__':
app.run(debug=True)
and here is my html file I saved my form in name.html
{% extends 'base.html' %}
{% block content %}
<!-- <h1>What's Your Name?!</h1> -->
{% if name %}
<h1>Hello {{ name }}!!!</h1>
{% else %}
<h1>What's Your Name?</h1>
<br/>
<form method="POST">
{{ form.hidden_tag() }}
{{ form.name.label }}
{{ form.name() }}
<br/>
</form>
<button>
{{ form.submit() }}
</button>
{% endif %}
{% endblock %}