我目前无法显示搜索Twitter API推文的solr的json数据。
我想以表格形式显示它们,以便以后查看和添加其他UI内容更容易。
这是我的代码:
my views.py
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 })
我的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>
目前响应r.text以文本形式显示来自我的solr已爬网数据的查询a *的原始json。
所以我需要帮助将json数据处理成表格格式以显示在html中。