Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

260
Visualizações
Flask How can I do change for specific users

I am new to flask and I try to do a project that you do signup and if the admin press a button next to your name then the home page for the user will change. Here is the code of flask:

from flask import Flask,redirect,url_for,render_template,request,flash
from flask_sqlalchemy import SQLAlchemy
from flask_login import LoginManager,UserMixin,login_required,login_user,logout_user,current_user
from flask_wtf import FlaskForm
from wtforms import StringField,PasswordField
from wtforms.validators import InputRequired,Length
from werkzeug.security import generate_password_hash,check_password_hash
app = Flask(__name__)
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///users.db'
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
app.config['SECRET_KEY'] = 'abc'
db = SQLAlchemy(app)
class Users(db.Model):
    id = db.Column(db.Integer,primary_key=True)
    name = db.Column(db.String(200),unique=True,nullable=False)
    password = db.Column(db.String(200),unique=True,nullable=False)
    
db.create_all()

class RegisterForm(FlaskForm):
    name = StringField('Username',validators=[InputRequired(),Length(min=4,max=30,message='Name must be from 7 to 30')])
    password = PasswordField('Password',validators=[InputRequired(),Length(min=4,max=30,message='Password must be from 7 to 30')])


users = []
@app.route("/",methods=['POST','GET'])
def home():
    form = RegisterForm()
    try:
        if form.validate_on_submit():
            user = Users(name=form.name.data,password=form.password.data)
            db.session.add(user)
            db.session.commit()
            users.append(form.name.data)
            return redirect('/home')
    except:
        return 'Name doest exist'
    return render_template("register.html",form=form)

#You don't have now to log in to be admin
#For the Project only


a = 3
@app.route("/admin",methods=['POST','GET'])
def admin():
    if request.method == 'POST':
        global a
        a = 2
    return render_template("new3.html",mylist=users)
@app.route("/home")
def home1():
    return render_template("new4.html",r=a)
if __name__ == '__main__':
    app.run(debug=True)

And for the new3.html:

<!DOCTYPE html>
<html>
    <body>
        {%for i in mylist%}
            <p>{{i}}</p>
            <form action="" method="post">
                <button name='button1'>Press it</button>
            </form>
        {%endfor%}
    </body>

So how can I do that? I just want the change of home page to be only to the user that button pressed. I tried to do that by sending from email but I want to the change be on the home page.

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

The functionality you describe is built into HTML: The Ordered Llist. With some template code like:

<body>
  <ol>
    {% for b in bros %}
      <li>{{b}}</li>
    {% endfor %}
  </ol>
<body>

Renders in the browser like:

rendered

You need not manually deal with the count in your template, and items will appear in the HTML list in the same order as the python list myList (as python lists are ordered by default).

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda