I see, so I would import only the table I want? On Nov 11, 10:35 am, Wyatt Baldwin <[email protected]> wrote: > On Nov 10, 10:19 pm, Andrew <[email protected]> wrote: > > > > > Hi, > > > I'm currently learning pylons (and python) and would like some help on > > a project, I believe I have the right approach but I am not sure of > > how the MVC would be structured. > > > ==What I am trying to do== > > Let me explain a bit more of what I am trying to do. > > Suppose there is a database, exampledb, and I would like to be able to > > pull data out of that database (I am using SQLAlchemy and python > > MySQL), and display that data on a web page. > > > At the moment, I am able to display values I pull from the exampledb > > database on the console (using a simple controller script below) but I > > need some help using it with MVC and displaying on a webpage. > > > == What I Understand == > > - I understand the controller will call on the models or the views and > > return data to the model (please correct if this is wrong). > > The controller manipulates the model and returns data to the *view*. > > In Pylons, it might be more correct to say that the controller > interprets a request from the user, performs some kind of action > (which may or may not involve the model), and returns a rendered > representation of the result (could be HTML or JSON or XML, etc). > > > - The model is where I can put the database connection (for example, > > like the script below) and query and store the values into variables. > > - Then I would use a MAKO template to display those variables on a > > webpage, but I am not sure of how to assign the variables or define > > the function in the model/controller. > > > Can someone assist me with this please? Perhaps provide an example > > would be helpful! > > I would suggest going through one of the various Pylons tutorials. > This one might help, as it appears to address all your > questions:http://wiki.pylonshq.com/display/pylonscookbook/Making+a+Pylons+Blog > > > == Example of Controller.py == > > from sqlalchemy import * > > I know this is only an example, but please don't `import *` in real > code. > > > engine = create_engine('mysql://user:p...@localhost/exampledb > > charset=utf8&use_unicode=0') > > connection = engine.connect() > > > result = engine.execute("select field from exampledb") > > for row in result: > > print "name:", row['name'] > > result.close() > > > :::Note:::this only prints it to console
-- You received this message because you are subscribed to the Google Groups "pylons-discuss" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/pylons-discuss?hl=en.
