Python Django显示json数据表
我目前无法显示来自solr的json数据,solr可以抓取twitter API推文 我希望以表格的形式显示它们,以便以后更容易查看和添加其他UI内容 这是我的密码: 我的观点Python Django显示json数据表,python,json,django,solr,Python,Json,Django,Solr,我目前无法显示来自solr的json数据,solr可以抓取twitter API推文 我希望以表格的形式显示它们,以便以后更容易查看和添加其他UI内容 这是我的密码: 我的观点 def my_view(request): if request.method == 'POST': form = NameForm(request.POST) if form.is_valid(): gotName = form.cleaned_data['your_name']
def my_view(request):
if request.method == 'POST':
form = NameForm(request.POST)
if form.is_valid():
gotName = form.cleaned_data['your_name']
gotEmotion = form.cleaned_data['emotion']
gotWords = form.cleaned_data['words']
url = 'http://localhost:8983/solr/gettingstarted/query?q=id:' + gotName
r = requests.post(url, data={'id': gotName})
return render(request, 'index.html', {"table_data" : ??? })
#return render(request, 'index.html', {"mydata": mydata})
else:
not_working = "not working"
return render(request, 'index.html', {'text2': not_working })
my index.html表格部分:
<table>
# insert table formatting here
</table>
#在此处插入表格格式
完整index.html正文:
<body>
{% load static %}
<img src="{% static "/templates/happybird.jpg" %}"/>
<h1 style="text-align:center;">Emotional Tweets</h1>
<div class="container">
<div class="row">
<div class="col-md-12" >
<div class="input-group" id="adv-search">
<form action="/search/my_view/" method="POST">
{% csrf_token %}
{{ form }}
<div>
<input id="your_name" type="text" class="form-control" name="your_name" placeholder="Search for Tweets" value="{{ current_name }}" />
<br>
</div>
<div class="form-group">
<label for="filter">Filter by</label>
<select class="form-control">
<option value="0" selected>All Tweets</option>
<option value="1">Excited</option>
<option value="2">Happy</option>
<option value="3">Neutral</option>
<option value="4">Sad</option>
<option value="5">Angry</option>
</select>
</div>
<div class="form-group">
<label for="contain">Contains the words</label>
<input id="words" class="form-control" type="text" name="words" value="{{ current_words }}" />
</div>
<input type="submit" value="OK">
</form>
</div>
</div>
</div>
</div>
</div>
<p>{{ text2 }}</p>
<p>{{ text3 }}</p>
<table>
# insert table formatting here ???
</table>
<script type="text/javascript">
</script>
</body>
{%load static%}
情感推文
{%csrf_令牌%}
{{form}}
过滤
所有推文
兴奋的
高兴的
中立的
悲哀的
愤怒的
包含单词
{{text2}
{{text3}}
#在这里插入表格格式???
当前,响应r.text以文本形式显示来自我的solr爬网数据的查询a*的原始json
因此,我需要帮助将json数据处理成表格格式,以在html中显示