简体   繁体   中英

Django + SQLAlchemy + RESTful API (tastypie?)

I am currently using Django with SQLAlchemy, and would like to implement an (simple to begin with) API for mobile devices.

Am evaluating at different python RESTful API frameworks, particularly tastypie and piston.

Can someone please point me to the right direction re: using either modules to bind resources to SQLAlchemy?

Alternatively, any other frameworks that'd work better with Django+SQLAlchemy?

Thanks guys.

You might want to take a look at the following page in the tastypie documentation:

http://django-tastypie.readthedocs.org/en/latest/non_orm_data_sources.html

Specifically, the riak example seems good and the kind of thing that you need to implement.

Tastypie does work with SQLAlchemy.

Check out tastyalchemy @ github - it is a good start for how to build a SQLAlchemyResource for Tastypie. Using it, you can create a resource for an SQLAlchemy ORM class like:

class MyORMResource(SQLAlchemyResource):
    class Meta:
        resource_name = 'myorm'
        object_class = MySQLAlchemyORMClass
        allowed_methods = ['get', 'post', 'put', 'delete']

I found I needed to implement SQLAlchemyResource.post_detail() to get the updating to work, and I handle my sessions differently so I had to change a few things, but if you don't mind reading through tastypie's resource.py it is pretty easy to get up and running. Foreign keys work too, although haven't found a way to get a One to Many relationship to work yet.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM