我试图显示一个图形,该图形响应用户从选择表单中选择的选项。然而,我发现,当我选择“BTC”之外的其他选项时,图形并没有做出响应
相关main.HTML:
<div class = "container">
<form method = "POST" action = "">
<select name = "coin-select">
{% for coin in coin_lst %}
<option value="{{ coin }}">{{ coin }}</option>
{% endfor %}
</select>
</form>
</div>
<div class = "container">
{% autoescape off %}
{{ graph }}
{% endautoescape %}
</div>
relevent view.py:
def initial_data(request):
coin_lst = []
for x in focused_df.coin:
if x not in coin_lst:
coin_lst.append(x)
def close_vs_redditComments():
if request.method == 'POST':
coin = str(request.POST.get("coin-select"))
else:
coin = 'BTC'
closeVSredditComment = make_subplots(specs=[[{"secondary_y": True}]])
closeVSredditComment.add_trace(go.Scatter(x = df[df.coin == coin]['time'], y = df[df.coin == coin]['close'], name = "closing price"), secondary_y = False)
closeVSredditComment.add_trace(go.Scatter(x = df[df.coin == coin]['time'], y = df[df.coin == coin]['reddit_comments'], name = "reddit comment volume"), secondary_y = True)
return(plot(closeVSredditComment, output_type = 'div'))
context = {
'coin_lst': coin_lst,
'graph': close_vs_redditComments()
}
return render(request, 'main.html', context)
我错过了什么
您应该尝试在Django中对当前HTML使用AJAX
您可以在本文中阅读有关实现的详细信息: https://simpleisbetterthancomplex.com/tutorial/2016/08/29/how-to-work-with-ajax-request-with-django.html
相关问题 更多 >
编程相关推荐