Does anyone know about python flask and wtf forms?....

Click For Summary
SUMMARY

This discussion focuses on implementing user registration forms in a Flask application using WTForms. The key components include the creation of a RegistrationForm class that utilizes fields such as StringField and PasswordField with specific validators for username, email, and password confirmation. The HTML structure for the form is provided, along with a request for assistance in modifying the CSS for better layout and understanding the necessity of InputRequired() versus DataRequired() validators. The discussion highlights the importance of proper form validation in web applications.

PREREQUISITES
  • Flask framework knowledge (version 2.x recommended)
  • Understanding of WTForms library (version 2.3.x)
  • Basic HTML and CSS for form layout
  • Familiarity with form validation concepts
NEXT STEPS
  • Explore Flask form handling with Flask-WTF for enhanced features
  • Learn about custom validators in WTForms
  • Investigate CSS layout techniques for forms, including Flexbox and Grid
  • Review Flask's routing and request handling for form submissions
USEFUL FOR

Web developers, particularly those working with Flask and WTForms, as well as front-end developers looking to improve form design and validation techniques.

gtguhoij
Messages
33
Reaction score
2
TL;DR
I am trying to space the forms in the registration route but it is not working.
[CODE lang="python" title="flaskblog.py"]from flask import Flask, render_template
from forms import RegistrationForm

@app.route("/register", methods = ['POST', 'GET'])
def register():
forms = RegistrationForm()
return render_template('register.html',form=forms)[/CODE]

[CODE lang="python" title="forms.py"]
from wtforms import Form, BooleanField, StringField, PasswordField, validators
# what does Form do
class RegistrationForm(Form):
username = StringField('Username', [validators.Length(min=2, max=25)])

email = StringField('Email', [validators.Length(min=4, max=25)])

password = PasswordField('New Password', [
validators.DataRequired(),
validators.EqualTo('confirm', message='Passwords must match')
])

confirm_password = PasswordField('Repeat Password')[/CODE]

[CODE title="register.css"]
label
{
display: block;
}
[/CODE]
[CODE lang="html" title="register.html"]<!DOCTYPE html>
<html>
<head>
<title> register </title>
<link rel="stylesheet" type="text/css" href="register.css"/>
</head>
<body>
<form action="/register" id="register_forms" method="POST">
fields/16379203 -->
<label for="username">
Username
{{(form.username)}}
</label>

<label for="email">
Email
{{form.email}}
</label>

<label for="password">
Password
{{form.password}}
</label>

<label for="password_form">
Confirm Password
{{form.confirm_password}}
</label>

<label>
<input type = "button" Submit value = "Submit" >
</label>
</form>
</body>
</html>[/CODE]

Here is the output I am trying to change.

 
Technology news on Phys.org
You can use break tags between each label to put it on a separate line Or you can use tables to organize the form in a row column format.

Basically, it’s the html, css files you need to change To get the format you want.
 

Similar threads

  • · Replies 9 ·
Replies
9
Views
3K
Replies
24
Views
2K
  • · Replies 2 ·
Replies
2
Views
1K