The TG2 quickstart command produces this basic TG site. Here's how it works.
When you want a model for storing favorite links or wiki content, the
/model
folder in your site is ready to go.
You can build a dynamic site without any data model at all. There still be a default data-model template for you if you didn't enable authentication and authorization in quickstart. If you have enabled authorization, the auth data-model is ready-made.
The "root.py
" file under the /controllers
folder has
your URLs. When you called this url (about
), the command went through the
RootController class to the about()
method.
Those Python methods are responsible to create the dictionary of variables that will be used in your web views (template).
A web page viewed by user could be constructed by single or several reusable
templates under /templates
.
Each projects gets quickstarted with a master.html
template and a bunch of templates for the pages provided by the RootController.
The master.html template controls the overall design of the page we're looking at. It draws the headers, the footer, the notices flash and embeds the content of each page of your web applications. Thus the "master.html" template provides the overall architecture for each page in this site.
There's more to the "master.html" template... study it to see how the <title> tags and static JS and CSS files are brought into the page. Templating with Genshi is a powerful tool and we've only scratched the surface. There are also a few little CSS tricks hidden in these pages, like the use of a "clearingdiv" to make sure that your footer stays below the sidebars and always looks right. That's not TG2 at work, just CSS. You'll need all your skills to build a fine web app, but TG2 will make the hard parts easier so that you can concentrate more on good design and content rather than struggling with mechanics.
If you have access to this page, this means you have enabled authentication and authorization in the quickstart to create your project.
The paster command will have created a few specific controllers for you. But before you go to play with those controllers you'll need to make sure your application has been properly bootstapped. This is dead easy, here is how to do this:
paster setup-app development.ini
inside your application's folder and you'll get a database setup (using the preferences you have set in your development.ini file). This database will also have been prepopulated with some default logins/passwords so that you can test the secured controllers and methods.
To change the comportement of this setup-app command you just need to edit
the websetup.py
file.
Now try to visiting the manage_permission_only URL. You will be challenged with a login/password form.
Only managers are authorized to visit this method. You will need to log-in using:
login: manager password: managepass
Another protected resource is editor_user_only. This one is protected by
a different set of permissions. You will need to be editor
with a
password of editpass
to be able to access it.
The last kind of protected resource in this quickstarted app is a full so called secure controller. This controller is protected globally. Instead of having a @require decorator on each method, we have set an allow_only attribute at the class level. All the methods in this controller will require the same level of access. You need to be manager to access secc or secc/some_where.