如何在My Django应用程序中显示我从public_tweets = api.home_timeline()获得的对象?

时间:2016-06-12 23:30:00

标签: python django api twitter tweepy

编辑我是新来的,所以请原谅我不太了解,我刚开始在我的django应用程序中搞砸了tweepy。我想从

中提取对象
public_tweets = api.home_timeline()

并在我的django模板中显示它们。我试过这个

    CONSUMER_KEY = 'jk'
CONSUMER_SECRET = 'op'
OAUTH_TOKEN = 'o-'
OAUTH_TOKEN_SECRET = 'jo'


auth = tweepy.OAuthHandler(CONSUMER_KEY, CONSUMER_SECRET)
auth.set_access_token(OAUTH_TOKEN, OAUTH_TOKEN_SECRET)

api = tweepy.API(auth)
user = api.get_user('raso0')

public_tweets = api.home_timeline()

context = {
    "tweets": public_tweets
    }

在我的模板中我做了

{{tweets}}

以及

 {% for t in tweets %}
  {{t}}
 {% endfor %}

这些都没有奏效。我的最终目标是在Twitter中连接顶级主题标签以及与之相关的用户。但主要是为了获得顶级哈希标签,用户是次要的,任何有关如何使这项工作的帮助都会很棒。

编辑:

如果我这样做

print(public_tweets)

返回

 [Status(_json={{'coordinates': None, 'favorited': False, 
    'user': {
        'profile_background_color': '6789DE', 
        'profile_background_image_url_https': 
        'https://pbs.twimg.com/profile_background_images/378800000159753674/h4JqIjyc.jpeg', 
        'has_extended_profile': False, 'profile_sidebar_fill_color': 'FAF2E5', 
        'profile_background_tile': True, 
        'entities': 
            {'url': {
                'urls': [{
                    'indices': [0, 23], 
                    'url': 'https:///9M00f0rXzB', 
                    'display_url': 'UnivisionNoticias.com', 
                    'expanded_url': 'http://www.UnivisionNoticias.com'
                }]}, 
                'description': {'urls': [{'indices': [91, 114], 
                'url': 'https:///RNbRYjgZKb', 
                'display_url': 'uni.vi/STMDp', 
                'expanded_url': 'http://uni.vi/STMDp'}, 
                {'indices': [127, 150], 
                'url': 'https://De6i7jhLnU', 
                'display_url': 'uni.vi/STMKO', 
                'expanded_url': 
                'http://uni.vi/STMKO'}]}}, 
                'id': 35785401, 
                'statuses_count': 119247, 
                'listed_count': 6295, 
                'profile_banner_url': 
                'https://pbs.twimg.com/profile_banners/35785401/1459357894', 
                'profile_image_url': 
                'http://pbs.twimg.com/profile_images/715644463947776002/pO5EZh4S_normal.jpg', 
                'contributors_enabled': False, 
                'protected': False, 
                'default_profile': False, 
                'notifications': False, 
                'favourites_count': 4856, 'profile_text_color': '031441', 
                'profile_background_image_url': 
                'http://pbs.twimg.com/profile_background_images/378800000159753674/h4JqIjyc.jpeg', 
                'profile_sidebar_border_color': 'FFFFFF', 'geo_enabled': True, 'default_profile_image': False, 
                'created_at': 'Mon Apr 27 16:29:42 +0000 2009', 'name': 'Univision Noticias', 'time_zone': 'Eastern Time (US & Canada)', 
                'id_str': '35785401', 'profile_image_url_https': 'https://pbs.twimg.com/profile_images/715644463947776002/pO5EZh4S_normal.jpg', 
                'verified': True, 'url': 'https://9M00f0rXzB', 'is_translation_enabled': False, 'is_translator': False, 
                'follow_request_sent': False, 'followers_count': 1425477, 'location': 'Estados Unidos', 'friends_count': 1669, 
                'description': 'Noticias de la comunidad hispana y el acontecer mundial, al instante. Síguenos en Facebook https://RNbRYjgZKb e Instagram https:///De6i7jhLnU', 
                'profile_link_color': 'CB201D', 'screen_name': 'UniNoticias', 'profile_use_background_image': True, 'following': True, 'lang': 'es', 
                'utc_offset': -14400}, 'place': None, 'entities': {'media': [{'sizes': {'medium': {'h': 675, 'resize': 'fit', 'w': 1200},

如何在模板中显示此数据?

这些都没有奏效。我的最终目标是在Twitter中连接顶级主题标签以及与之相关的用户。但主要是为了获得顶级哈希标签,用户是次要的,任何有关如何使这项工作的帮助都会很棒。

0 个答案:

没有答案