コード例 #1
0
ファイル: helloworld.py プロジェクト: szarak/pygnite
#!/usr/bin/python
# -*- coding: utf-8 -*-

from pygnite import *

@get('/')
def index(request):
    return 'Hello world'


if __name__ == '__main__': pygnite(debug='www')
コード例 #2
0
ファイル: main.py プロジェクト: szarak/pygnite
def login(request):
    db.user.login.requires = IS_NOT_EMPTY()
    form = SQLFORM(db.user, fields=['login', 'password'])

    if FORM.accepts(form, request.vars):
        query = db((db.user.login == form.vars.login) &
                   (db.user.password == form.vars.password))

        if query.count() == 1:
            user = query.select()[0]
            request.session['user'] = Storage(login=user.login, id=user.id,
                                            email=user.email)
            request.session['flash'] = 'You\'ve been logged in'
            return redirect('/')
        else:
            request.session['flash'] = 'User not found'
            return redirect('/login')

    return render('form.html', form=form)

@get('/logout')
def logout(request):
    if request.session.has_key('user'):
        del request.session['user']

    request.session['flash'] = 'Bye, bye'
    return redirect('/')

if __name__ == '__main__': pygnite()