Am 18.09.2013 15:44, schrieb Sangram Kapre:
> Even I am looking for the same thing. I have learned about angularjs
> through some tutorial and I know how to create a RESTful web service using
> Python Flask. But I don't know how to make these two work together. I am
> thinking of keeping the structure of my web application same as that of
> angular-seed project on GITHUB. But now sure how to write python files
> that accept and fulfill the http requests made at front ends. Any help on
> this topic is much appreciated. Thanks you all.
In plain angular you can use $http, which does not expect anything, or
you can use $resource. $resource expects a certain (configurable) URL
layout, but is agnostic about the content. If you want to use $resource
you should start with angular 1.2(rc2) where it returns a promise.
Depending on your api you will be fine with a service that uses $http or
$resource.
There are some more feature rich REST-libs for angular. I couple
flask-restless with restangular. Restangular gives you an api to access
sub resources and works really well. It expects a different result
format and provides hooks to rewrite the received JSON to match it.
This is how I configure Restangular. It's mostly taken from a blog post
that I read back then, so kudos to the unknown writer.
angular.module('whateverApp', ['ngRoute', 'restangular'])
.config(function ($routeProvider, RestangularProvider) {
// configure restangular
RestangularProvider.setBaseUrl('/api');
// configure the response extractor for each request
RestangularProvider.setResponseExtractor(function(response, operation) {
// This is a get for a list
var newResponse;
if (operation === 'getList') {
// Return the result objects as an array and attach the metadata
newResponse = response.objects;
newResponse.metadata = {
numResults: response.num_results,
page:
response.page,
totalPages: response.total_pages
};
} else {
// This is an element
newResponse = response;
}
return newResponse;
});
..Carsten
> On Monday, January 21, 2013 6:03:53 AM UTC+5:30, Alexandru Geana wrote:
>>
>> Hello everybody, I was wondering if any of you guys is using Flask as a
>> backend with AngularJS. I tried to find some examples on how to do that but
>> nothing that I found was really helpful. I am interested on how to combine
>> these two, on the project structure an some basic CRUD operations.
>>
>> Any help will be much appreciated. Thank you!
>>
>
--
Carsten Senger - Schumannstr. 38 - 65193 Wiesbaden
sen...@rehfisch.de - (0611) 5324176
PGP: gpg --recv-keys --keyserver hkp://
subkeys.pgp.net 0xE374C75A