6 messages in com.googlegroups.pylons-discussRe: New to python & pylons| From | Sent On | Attachments |
|---|---|---|
| fintan | 28 Mar 2007 09:04 | |
| __wyatt | 28 Mar 2007 09:57 | |
| Shannon -jj Behrens | 28 Mar 2007 17:40 | |
| __wyatt | 28 Mar 2007 21:13 | |
| Jose Galvez | 29 Mar 2007 00:11 | |
| fint...@public.gmane.org | 01 Apr 2007 12:53 |
| Subject: | Re: New to python & pylons![]() |
|---|---|
| From: | __wyatt (wyat...@public.gmane.org) |
| Date: | 03/28/2007 09:57:22 AM |
| List: | com.googlegroups.pylons-discuss |
On Mar 28, 9:05 am, fintan
<fint...@public.gmane.org> wrote:
Hi
I'm new to python & pylons. I was wondering could someone answer some of my questions. I've got the basic down in python and was looking for a web framework when I came across pylons. I've gone through the tutorials and the documentation.
At the moment I'm building a user control panel that will integrate with ldap. So far I've managed to set up a login page with user level controls and am able to browse to different pages using links.
I'm trying to get some stuff straight in my head.
I've set up my database in models.__init__.py using sqlalchemy with mysql
Is this the correct method?
from docutils.core import publish_parts from sqlalchemy import * from sqlalchemy.ext.assignmapper import assign_mapper from pylons.database import session_context import pyucc.lib.helpers as h
meta = DynamicMetaData()
tables go here.
When I try to use
mytable = Table('Archive', meta, autoload = True)
from paster shell I get
File "/usr/lib/python2.4/site-packages/sqlalchemy/schema.py", line 51, in get_engine raise exceptions.InvalidRequestError("This SchemaItem is not connected to any Engine") sqlalchemy.exceptions.InvalidRequestError: This SchemaItem is not connected to any Engine
So I'm a little confused. Am I setting up the file right?
DynamicMetaData must be connected to an engine:
meta = DynamicMetaData() meta.connect(some_engine)
An engine is created for you when you do this:
from pylons.database import session_context
You can get at the engine with:
engine = session_context.current.bind_to meta.connect(engine)
Personally I find the way pylons.database works a little bit less explicit than I would like. Another way to create an engine is:
from pylons.database import create_engine, get_engine_conf engine = create_engine(*get_engine_conf()) metadata.connect(engine)
``get_engine_conf`` magically looks up your sqlalchemy settings from the ini file you're using:
# development.ini # other settings here [app:main] # other app:main settings here sqlalchemy.dburi = postgres://bycycle:pants@localhost/bycycle sqlalchemy.echo = true
I've defined the tables using the long method to get around this.
For each table do I have to set up a class to access that table? Kinda of like the routing? Should they be in separate files under models or in the same file __init__.py? Thanks in advance
I'd recommend checking out this related post and the post it links to:
__wyatt




