Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Python

Nicolas Sandller
Nicolas Sandller
5,643 Points

RESTful api in django?

Kenneth,

can we see a course on how to implement a django RESTful api server? Are there some useful tips on how to start with this?

How do we set up django to receive requests from different adresses (COURS)?

I think maybe this https://github.com/wq/django-rest-pandas would be great but I don't yet understand how to install it and make it work. I need this for data science purposes. I would need to:

-make a request to the django on my server -django would hve to make some operations, and evaluate some models -receive the response to my js frontend.

Is this possible?

Thanks!

1 Answer

Kenneth Love
STAFF
Kenneth Love
Treehouse Guest Teacher

Hey, thanks for the questions.

I'd probably use django-rest-framework for building a RESTful API in Django. I haven't seen REST Pandas before but that looks like a pretty neat package.

For CORS, that's going to be handled by your server, not Django itself. It probably won't even come up, though, because you're requesting the endpoint of an API, instead of a static asset. Still, your server (Apache, nginx, etc) would handle that.

You could, of course, built this already. Build a view that returns JSON after doing whatever operations you need. Make sure to change the response type.

Nicolas Sandller
Nicolas Sandller
5,643 Points

Kenneth Love, I absolutely loved your answer. Thank you so much for being on top of every question!!! :)

I will start with your suggestion by building a view that returns a VIEW. And I'll go for the rest-framework after.

Thank you!