0

I'm using django. I get data from a website and I can see it on the pandas and console as in the picture.

How do I export this to the django html file?

I'm actually passing the variable named "morning_star" but I can't show it.

view.py

from django.shortcuts import render
from binance.client import Client
import talib
import pandas as pd


def home_view(request):
    client = Client("12",
                    "12")

    pd.set_option('display.max_rows', None)
    klines = client.get_klines(symbol="VETUSDT", interval="15m", limit=100)

    labels = ['T', 'open', 'high', 'low', 'close', 'V', 'CT', 'QV', 'N', 'TB', 'TQ', 'I']

    df = pd.DataFrame(klines, columns=labels)
    candles_df = pd.DataFrame(klines,
                              columns=['T', 'open', 'high', 'low', 'close', 'V', 'CT', 'QV', 'N', 'TB', 'TQ', 'I'])

    morning_star = talib.CDLMORNINGSTAR(candles_df['open'], candles_df['high'], candles_df['low'],
                                        candles_df['close'], penetration=0)
    engulfing = talib.CDLENGULFING(candles_df['open'], candles_df['high'], candles_df['low'], candles_df['close'])

    candles_df['morning_star'] = morning_star
    candles_df['engulfing'] = engulfing

    print(candles_df)

    context = {
        'morning_star': morning_star
    }
    return render(request, 'home.html', context)

Home.html

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body> Home page 
{{ morning_star }}
</body>
</html>
Fatih mzm
  • 395
  • 1
  • 7
  • 21

1 Answers1

0

I had the same problem and this is how it was solved #views.py

return render(request, 'home.html', context=context)

#Home.html

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body> Home page 
{{%for m in morning_star %}}
<ul>
<li>
{{ m }}</li>
</ul>
{{%endfor%}}
</body>
</html>
Yas Sm
  • 7
  • 1
  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Apr 20 '23 at 13:50