Ask Your Question

How can develop some API?

asked 2016-02-25 20:28:17 -0600

Andy gravatar image

updated 2016-03-06 19:50:35 -0600

In my forum,I want to get question based on keyword from API.For example,

[my site]/api/getquestions/?query=$keyword

it can return all the question I want.In the other side, I want to get a user's inboxs.

[my site]/api/getInbox/userid


edit retag flag offensive close merge delete



In English, please add a space after each comma, like this, and after each period ending a sentence. Like this. (In what you wrote,they are missing.Like this.)

slelievre gravatar imageslelievre ( 2016-02-26 10:15:44 -0600 )edit

1 Answer

Sort by ยป oldest newest most voted

answered 2016-03-06 19:53:52 -0600

Andy gravatar image

updated 2016-03-06 19:58:18 -0600

I have solved my question myself.

here is the key code below.

def inbox(request, account_id):

Gets a single question
#print repr(account_id)
user = get_object_or_404(User, last_name=account_id)
data = get_user_data(user)
#print repr(data)
activity_types += (const.TYPE_ACTIVITY_MENTION,)
memo_set = user.get_notifications(activity_types)

memo_set = memo_set.select_related(

response_list = list()
for memo in memo_set:
    obj = memo.activity.content_object
    if obj is None:
        continue#a temp plug due to bug in the comment deletion

    act = memo.activity
    act_user = act.user
   act_message = act.get_activity_type_display()
    act_type = 'edit'

    response = {
        'timestamp': str(act.active_at),
        'user': str(act_user),
        'is_new': memo.is_new(),
        'url': act.get_absolute_url(),
        'snippet': act.get_snippet(),
        'title': act.question.thread.title,
        'message_type': act_message,
        'memo_type': act_type,
        'followup_messages': list(),
        'content': obj.html or obj.text,

    if memo.is_new():

json_string = simplejson.dumps(response_list)
return HttpResponse(json_string, content_type='application/json')
edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower


Asked: 2016-02-25 20:28:17 -0600

Seen: 903 times

Last updated: Mar 06 '16