简体   繁体   中英

Setting up a RESTful api with Django, pre-existing models

So I'm currently tasked with creating a web api for a systems database that I manage, and already have an existing django site with models and such created. What would be the best tool to create an api to work with my existing models and framework? Everything I'm looking at (tastypie, django rest framework) seems to want me to recreate my models using their serializer objects. Is that my only choice if I want to implement a RESTful api? Sorry if this is a dumb question, I've never created an API before and am just attempting to figure things out.

To reiterate, attempting to create an API for django with pre-existing models, what tool should I use?

Thanks!

I recommend you to use Django REST framework since I'm using it and satisfied with the result. One more bonus point is its author is active on StackOverflow, you can ask question anytime.

One can choose Tastypie over DRF. Well it's just the matter of taste. I can say both are equally good.

And no you don't have to recreate your models, creating serializer class is even easier than creating form from models in Django.

If you don't want to use DRF or Tastypie, fine, you can always build an API yourself with just normal views. But soon you will face the wall of serializing object, complex URL design, and other sorts of problems.

It's up to you to decide which path you want to go.

I would also recommend using Django Rest Framework but if you're interested in a simple solution to work with existing models, take a look at https://github.com/tomchristie/django-auto-api (same author as Rest Framework). It allows you to easily expose existing models in multiple formats and is really simple to integrate into your app.

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