views:

146

answers:

2

I'm new to python, and starting to learn website development with pylons and sqlalchemy.

I've read the document of sqlalchemy and pylons, but still have a lot of problems. I've tried 2 days, but a simple website with basic CRUD operations can't work yet. I met some big problems(for me), that the circular imports problem, and relationship between models. I want to ask them here, but I know little about python, it's a problem for me to ask too.

I'm looking for an example application using pylons and sqlalchemy, I've googled, but not found. Where can I found it? Thanks in advance!

+3  A: 

You should probably start looking from here, http://wiki.pylonshq.com/display/pylonscommunity/Sites+Using+Pylons as many of them are open-source.

Another source would be PyPI: http://pypi.python.org/pypi?%3Aaction=search&term=pylons&submit=search

Good (but complex) example on Pylons + SQLA is reddit: http://code.reddit.com/browser/r2/r2/

I met some big problems(for me)

It easier to just ask about these particular problems, though, rather than trying to understand existing code. Sites like reddit use some un-intuitive code.

circular imports problem

Just use single module per class and there will be no problems. When it is absolutely nessesary that class X and class Y able to use each other, use

from .y import Y
Class X(Base):
    ...
    y = relation(Y, backref="x")

Class Y(Base):
    ...
    @classmethod
    def get_x(cls):
        return cls.x.attr.target_mapper.class_

This is a bit hackish, but lets you create circular reference. Other way would be to add X into module y namespace from module x explicitly.

Daniel Kluev
@Daniel, thank you so much for your answer! I'm visiting these websites now
Freewind
+3  A: 

You should read The Pylons Book.

wRAR
It is outdated and should not be used as reference for now.
Daniel Kluev
@wRAR, it's still useful for me, thank you
Freewind
Agree even if it's outdated it's still very useful to start using pylons
sptremblay