mirror of
https://github.com/StefBuwalda/WebTech.git
synced 2025-10-30 03:10:00 +00:00
Adding forms testing
This commit is contained in:
BIN
__pycache__/forms.cpython-312.pyc
Normal file
BIN
__pycache__/forms.cpython-312.pyc
Normal file
Binary file not shown.
13
forms.py
Normal file
13
forms.py
Normal file
@@ -0,0 +1,13 @@
|
||||
from flask_wtf import FlaskForm
|
||||
from wtforms import StringField, SubmitField, URLField
|
||||
from wtforms.validators import DataRequired
|
||||
|
||||
|
||||
class ServiceForm(FlaskForm):
|
||||
naam = StringField("Service naam:", validators=[DataRequired()])
|
||||
url = URLField("Service URL:", validators=[DataRequired()])
|
||||
submit = SubmitField("Toevoegen")
|
||||
|
||||
|
||||
class LoginForm(FlaskForm):
|
||||
pass
|
||||
16
run.py
16
run.py
@@ -1,7 +1,9 @@
|
||||
from flask import Flask
|
||||
from flask import Flask, render_template, session
|
||||
from forms import ServiceForm
|
||||
|
||||
# Create Flask instance
|
||||
app = Flask("__name__")
|
||||
app = Flask(__name__)
|
||||
app.config["SECRET_KEY"] = "mijngeheimesleutel"
|
||||
|
||||
|
||||
# Default app route
|
||||
@@ -11,6 +13,16 @@ def index():
|
||||
return "<h1>This is the default page</h1>"
|
||||
|
||||
|
||||
@app.route("/forms")
|
||||
def forms():
|
||||
service_form = ServiceForm()
|
||||
|
||||
if service_form.validate_on_submit: # type: ignore
|
||||
session["name"]
|
||||
|
||||
return render_template("forms.html", form=service_form)
|
||||
|
||||
|
||||
# Prevent execution when imported by other script
|
||||
if __name__ == "__main__":
|
||||
# Start the flask server in debug mode for development purposes
|
||||
|
||||
23
templates/forms.html
Normal file
23
templates/forms.html
Normal file
@@ -0,0 +1,23 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Testing</title>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<h1>Hallo</h1>
|
||||
<form method="POST">
|
||||
{{ form.hidden_tag() }}
|
||||
{{ form.naam.label }} {{form.naam}}
|
||||
<br>
|
||||
{{ form.url.label}} {{form.url}}
|
||||
<br>
|
||||
{{ form.submit() }}
|
||||
</form>
|
||||
|
||||
</body>
|
||||
|
||||
</html>
|
||||
Reference in New Issue
Block a user