Note that there are some explanatory texts on larger screens.

plurals
  1. POWhy isn't tastypie easily usable by other parts of my service? I have duplicate codes in tastypie resource and my core service
    text
    copied!<p>I spent whole week to integrate tastypie into my project and now I can't stop think 'why did I do it'. </p> <p>I'm using django and tastypie(REST framework) but my question could be applied to other language/frameworks. </p> <p>My requirements are<br> 1. mobile clients requesting json<br> 2. web clients requesting html and json</p> <p>So I had</p> <blockquote> <ol> <li>end_point for json requests(eg, give me images of this user)</li> <li>end_point for html requests(give me a user home page with his images and etc)</li> <li>core_service(at the bottom) which returns list of images dictionary to #1 and #2</li> </ol> </blockquote> <pre><code>def user_image_list_json(request): # 1 dict = service.user_image_list(request.user_id) return serialize_as_json(dict) def user_home(request): #2 #build other parts of user home such as `user name` dict = service.user_image_list(request.user_id) #stuff that dict inside html #build other parts of the page return html_response #3 def image_list_user(user_id, last_image_id,request_comment_count, count): if last_image_id is not None: last_image_id = int(last_image_id) queryset = AlbumImage.objects.select_related().filter(id__lt=last_image_id).filter(album__user_profile__user__id = user_id) else: queryset = AlbumImage.objects.select_related().filter(album__user_profile__user__id = user_id) if count is not None: count = min(IMAGE_LIST_COUNT, count) queryset = queryset[0:count] else: count = IMAGE_LIST_COUNT album_image_list = list(queryset) #dict_list = [album_image.to_dict() for album_image in album_image_list] dict_list = append_comment_list(album_image_list,request_comment_count) return dict_list </code></pre> <p>That's how I structured my web service to serve web client and mobile client.<br> Now I hear REST framework would ease the web development.(This is my first web development)<br> I adapt tastypie (a django/python REST api framework) </p> <p>I expected tastypie would replace my code at level #3(the common_service).<br> But I find it's actually #1/#3 tied together. </p> <p>If my understanding is correct, I'll end up with </p> <blockquote> <ol> <li><s>end_point for json requests(eg, give me images of this user)</s></li> <li>end_point for html requests(give me a user home page with his images)</li> <li>core_service(at the bottom) which returns python dictionary to #1 and #2</li> <li>tastypie which act as combination of #1/#3</li> </ol> </blockquote> <p>So I still need #3.(the core service) even when I have tastypie.<br> I find it weird...</p> <p><a href="https://stackoverflow.com/questions/14647819/using-tastypie-api-from-other-views">Using tastypie api from other views</a> is my related question. </p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload