Eralde
Eralde

Reputation: 21

python/pylons - multiple controllers for template

I have a main page in Python/Pylons project, which have multiple different blocks (e.g. news/demo/(registration|private zone)/...).

My thought is that each block should be generated in a separate controller. How can I call another controller method in a main page controller?

Upvotes: 2

Views: 389

Answers (2)

Brighid McDonnell
Brighid McDonnell

Reputation: 4343

This is probably where you start moving chunks of code to library functions, to the /lib part of your Pylons project. "Generated by a separate controller" is probably going too far - you merely need to not repeat yourself. Try using library functions to make sure that the correct data is available, then use Mako's inheritance and namespace features.

Upvotes: 0

Antoine Leclair
Antoine Leclair

Reputation: 18050

What you want to do is HMVC. I'm not sure it is easily doable out of the box with Pylons, since it's MVC.

If you have code that is repeated in multiple controllers, you could move some of this code out of the controller (in the models, or another module).

Also, if you are using Mako templates, you can reuse parts of templates by using inheritance http://www.makotemplates.org/docs/inheritance.html and by using defs http://www.makotemplates.org/docs/defs.html.

Upvotes: 1

Related Questions