Here's my html for my Django Twitter project. I am trying to embed tweets in Django
<html lang="en"> <h1>Tweets</h1> <form action="" method="post"> {% csrf_token %} {{ form }} <button type="submit">Submit</button> </form> <body> {% if tweets %} <p>{{tweets}}<script async src="https://platform.twitter.com/widgets.js" charset="utf-8"></script></p> {% endif %} </body> </html> Here's my views.py:
import tweepy from tweepy.auth import OAuthHandler from .models import Tweet from .models import Dates from django.core.paginator import Paginator, EmptyPage, InvalidPage from django.shortcuts import render from django.db import models, transaction from django.db.models import Q import os import tweepy as tw from .forms import TweetIDForm from django import template import requests consumer_key = 'dddddd' consumer_secret = 'cccccc' access_token = 'dddddd' access_token_secret = 'ccccc' def clean_tweet_id(request): # if this is a POST request we need to process the form data if request.method == 'POST': # create a form instance and populate it with data from the request: form = TweetIDForm(request.POST) print(form) # check whether it's valid: if form.is_valid(): # process the data in form.cleaned_data as required tweet_id = form.cleaned_data.get("tweet_id") #act = form.cleaned_data.get("action") auth = tw.OAuthHandler(consumer_key, consumer_secret) auth.set_access_token(access_token, access_token_secret) api = tw.API(auth, wait_on_rate_limit=True) twtjson = requests.get('https://publish.twitter.com/oembed?url=' + tweet_id + '&omit_script=true') tweets = twtjson.json() tweet = tweets.get('html') return render(request, 'tweet/tweet-list.html', {'form': form, 'tweet_id':tweet_id, 'tweets': tweet}) My code works so far, but for some reason it does not show the actual tweet, but it merely shows the HTML and not the actual tweet like it would be embedded on another site. I am trying to create an app where the user inputs the tweet URL and the tweet will be embedded itself. I worked for a couple days and it still does not work.