Need some more detailed tutorial on flask tryton

Hey guys
Can anyone teach me(or point me to a site) on how to do flask tryton in more detail than what is on the py website?

1 Like

I think there is no such documentation (or at least we are not aware of it).

If you want to learn how to use flask-tryton I will recomend learing first the flask basics and also the tryton basics. Once you are familiar with both concepts using flask-tryton is easier.

What basics do i need to learn in tryton?

You need to know how the tryton ORM works as normally flask tryton interact with tryton models to use its data.

Once you have this it depends on the application but you will need to know how the modules you have activated in the database are designed in order to follow it’s usages from flask tryton.

Here is an example which uses flask-tryton and web_user for authentication:

Click to show the example
from flask import Flask
from flask_tryton import Tryton
from flask.ext.babel import Babel

app = Flask(__name__)      
babel = Babel(app)                                                             
app.config['TRYTON_DATABASE'] = os.environ.get('DB_NAME', 'tryton') 
tryton = Tryton(app, configure_jinja=True)

WebUser = tryton.pool.get('web.user')                                          
Session = tryton.pool.get('web.user.session')                                                                                

def login_required(func):                                                      
    def wrapper(*args, **kwargs):                                              
        session_key = None                                                     
        if 'session_key' in session:                                           
            session_key = session['session_key']                               
        user = Session.get_user(session_key)                                   
        if not user:                                                           
            return redirect(url_for('login', next=request.path))               
        return func(*args, **kwargs)                                           
    return wrapper                                                             

class LoginForm(FlaskForm):                                                    
    email = StringField('Correo Electrónico',                                  
        render_kw={'placeholder': 'Correo Electrónico'})                       
    password = PasswordField('Contraseña',                                     
        render_kw={'placeholder': 'Contraseña'})                               

@app.route('/login', methods=['GET', 'POST'])                                  
def login():                                                                   
    form = LoginForm()                                                         
    if request.method == 'POST' and form.validate_on_submit():                 
        user = WebUser.authenticate(,       
        if user:                                                               
            session['session_key'] = WebUser.new_session(user)                 
            flash('Ahora estas identificado.', 'success')                      
            return redirect(request.form.get('next', url_for('index')))        
        flash('Email o contraseña incorrectos.', 'error')                      
    return render_template(                                                    

def logout():                                                                  
    if session['session_key']:                                                 
                ('key', '=', session['session_key']),                          
        session.pop('session_key', None)                                       
        flash("Se ha desconectado tu sessión", 'success')                      
    return redirect(url_for('index')) 

def index():                                                                   
    return render_template('index.html')    

def account():                                                                 
    return render_template('account.html')                                           

This example was mentioned on #tryton IRC channel by @pokoli.