Saturday, January 30, 2021

web2py vers py4web

 des pointeurs

1/ mail dans la liste web2py

think it depends on your web2py code, tried before it takes days to make it run smoothly port http://sugizo.pythonanywhere.com/music into py4web

things to consider 
- copy web2py models, controllers and modules files into py4web app folder
better focus on models first after it work smooth on py4web then do the controllers and modules files
- add db.commit() in every define table
- in __init__.py
put all models define table files (so that can be access on _dashboard) and every python files that can be access from browser

controllers and modules part
- add db.commit() in every table activities : insert(), update(), delete()
- put @action(), @action.uses() in every python function that can be access from web browser
- if use web2py response then you can search and replace it
- if use web2py request.vars, in py4web use request.json or request.query
and 
web2py request.args in py4web the args is define on @action() decorator and python function name
- move web2py variables (mutable) inside the function that use itnever define it as global variables or will get unexpected weird result with no error traceback occured
- if use web2py SQLFORM() or SQLFORM.grid() in py4web use Form()
while web2py has FORM() please consider the signature (parameter that build it), not everything is same
even better define form in html yourself (IMO), so you cut about migration FORM(), SQLFORM() above
- if use web2py that use module files, search module function and delete its module file name to make it work in py4web
- if use web2py modules files find current. and delete it in py4web app

views part
- in web2py views copy into py4web app templates
- in py4web templates folder 
search {{ and replace it with [[ 
and 
}} and replace it with ]]
- if use web2py ajax(), then you can consider replace the code with Q.ajax() in py4web or even better modify your code to use javascript on html files

there's many more, it's just experienced porting http://sugizo.pythonanywhere.com/music into py4web

objective
move define table files into models folder, accessed python function from browser into controllers folder and python function into modules folder, because put everythings in app folder make it a lot of files on it, better to make it organize into separate folders like web2py

question
is there any simple example how to make py4web execute python into separate subfolder ?

tried it before have face an error about variable define on common.py (db, T)
 
 
 
LIens
 
dasjboards for web2py https://github.com/ali96343/facew2p
dashboards  for py4web https://github.com/ali96343/facep4w
charts Highcharts.js
 
 doc de py4web

No comments:

Post a Comment

Ma journée du 01 Décembre 2025

En ce premier jour de décembre, l'heure est venue, De conter une histoire, par les dés soutenue. Quinze dés ont roulé, offrant leur dest...