custom path to vires

39 views
Skip to first unread message

xgp.l...@gmail.com

unread,
Apr 29, 2026, 7:09:59 PMApr 29
to py4web
Hi all,

Question: i dont want to use the template folder for my views, but i find its not possible. I had to modify the py4web/core.py to allow a custom path to my views.

Image

Is there any other way to allow custom path to views?

Dave S

unread,
May 1, 2026, 10:26:11 PMMay 1
to py4web
I don't have an answer.

I don't know if Massimo is still traveling.  I would pick Nico, Lucas, and Alan as being fairly knowledgeable on the internals.  Nico and Luca De Alfaro have also worked on the docs and training materials.

There is this slightly related old thread

Good luck!

/dps

pe...@anewalt.com

unread,
May 4, 2026, 5:55:34 PMMay 4
to py4web
Here's what I do for that - I prefer a structure where controllers and templates can be in the same folder, so I define a decorator function that I use everywhere in place of @action.uses().  That function looks for a template name with a slash in it, which indicates it's somewhere other than the location defined by settings.TEMPLATE_FOLDER.  (I also use this function to pass a bunch of objects that my templates always seem to need...)  Here's that function:

def default_uses(template, *extraObjs, **extraInjects):
    if (index := template.rfind('/')) > 0:      # accommodate a structure where templates and controllers are in the same folder
        template_path = template[0:index]       # templates are found in TEMPLATE_FOLDER unless a different path is specified
        template = template[index+1:]           # templates in other folders need to reference inclusions ie. [[include '../templates/file.html']]
        t = Template(template, path=os.path.join(settings.APP_FOLDER, template_path))
    else:
        t = Template(template, path=settings.TEMPLATE_FOLDER)
    return action.uses(t, session, auth, db, T, Inject(g=g, auth=auth, settings=settings, request=request, response=response, T=T), *extraObjs)

Then in a controller:
@action('attendee_signup',  method=["GET","POST"])    
@action('attendee_signup/<expo_code>',  method=["GET","POST"])    
@default_uses('expo/attendee_signup.html')
def attendee_signup(expo_code=None):
    ....

Hope that helps.
Reply all
Reply to author
Forward
0 new messages