开发者

Method for comparing twitter users to site users in Django / Python

This is a follow up to an earlier question. I'm using the below code to get a user's friends and then compare the开发者_如何学编程m to the users of my site to show a "Friends already using this site" list.

It's working perfectly, but is this an efficient way to do it? Any recommendations?

in views.py

# Get Twitter Friends
api = twitter.Api(consumer_key='TWITTER_TOKEN',
                      consumer_secret='TWITTER_SECRET',
                      access_token_key='request.user.get_profile.oauth_token',
                      access_token_secret='request.user.get_profile.oauth_secret')
friends = api.GetFriendIDs(request.user.username)

# Compare friends with High Five users    
profiles = Profile.objects.filter(twitter_id__in = friends['ids'])

in template.html

<h2>Friends</h2>
    <ul>
    {% for profile in profiles %}
        <li>
            <a href="/user/{{ profile.user.username }}">
                <img src="{{ profile.profile_image_url }}" />
            </a>
        </li>
    {% endfor %}
    </ul>


You're doing the right thing. What's your concern? Is the page loading slowly? If so, consider loading a page without this information, then using an ajax call to fetch the list of friends who are using the site. That way, at least you can have your user looking at a page with a loading graphic that says "fetching your list of friends....." instead of simply waiting a long time for the page to load.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜