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

In summary, The code initializes a Flask application and imports a RegistrationForm from the forms.py file. It then sets up a route for the registration page and renders a template for the register.html page with the registration form. The RegistrationForm class defines fields for username, email, and password, and includes validators for character length and password matching. The HTML form in register.html uses these fields and displays them with labels and input fields. The CSS can be modified to change the formatting of the form. It is recommended to use either break tags or tables to organize the form. Additionally, the use of InputRequired() or DataRequired() validators may depend on individual needs and preferences.
  • #1
33
2
TL;DR Summary
I am trying to space the forms in the registration route but it is not working.
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)

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')

register.css:
label
{
    display: block;
}
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>

Here is the output I am trying to change.

 
Technology news on Phys.org
  • #2
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.
 
  • #3
Last edited:

What is Python Flask?

Python Flask is a popular web framework for building web applications in the Python programming language. It is known for its simplicity, flexibility, and ease of use.

What is WTF Forms?

WTF Forms is an extension of Python Flask that simplifies the process of creating and validating web forms. It provides reusable form components and built-in validators to ensure data is entered correctly.

How do I install Python Flask and WTF Forms?

To install Python Flask and WTF Forms, you will need to have Python installed on your computer. Then, you can use a package manager like pip to install both Flask and WTForms. Detailed installation instructions can be found on their respective websites.

What are the benefits of using Python Flask and WTF Forms?

Python Flask and WTF Forms offer a variety of benefits, including a simple and intuitive syntax, built-in support for unit testing, and a large community of developers for support and resources. They also allow for easy integration with other Python libraries and databases.

Are there any limitations to using Python Flask and WTF Forms?

While Python Flask and WTF Forms offer many advantages, they may not be the best choice for all web applications. They may not be suitable for large and complex projects, and may require additional extensions for certain features. It is important to assess the needs of your project before deciding on a web framework.

Similar threads

  • Programming and Computer Science
Replies
9
Views
2K
  • Programming and Computer Science
Replies
24
Views
1K
  • Programming and Computer Science
Replies
2
Views
839
Back
Top