![](/img/trans.png)
[英]How can I do: “As the the record button is pressed, the button will be flashing”
[英]How can i update firebase record using django views with new data when a button is pressed?
我正在开发一个仪表板,管理员可以在其中检索存储在 firebase 中的所有数据,然后对这些数据执行操作
我已经设法使用 django 视图在 firebase 中发布数据,我也可以使用视图在 html 表中检索相同的数据,但发现很难用新数据更新这些数据。
我的代码更新了 firebase 中的所有节点而不是只有一个节点 我知道我的问题是如何检索要更新的单个 id
我已经尝试了几种在线提供的解决方案,例如这个,但问题仍然存在
this is my deactivate_status.html
{% extends 'sidebar.html' %}
{% block body %}
<div class="container">
<h4>Home<b> ></b> Deactivated Service Providers</h4>
<div class="row">
<form id="form" method="POST" action = "/deactivate_status">
{% csrf_token %}
<table class="table" border="0.5">
<thead>
<tr style="font-size:larger">
<th>Username</th>
<th>Telephone</th>
<th>Profile Pic</th>
<th>Service</th>
<th>Status</th>
<th>Take Action</th>
</tr>
</thead>
<tbody>
<tr style="font-size:large">
{% for username,telephone,photo,service,status in combine %}
<td>{{username}}</td>
<td>{{telephone}}</td>
<div class="container1">
<td><img src="{{photo}}" style="max-width:20%; max-height:20%;cursor:pointer"
onclick="onClick(this)" class="modal-hover-opacity"></td>
</div>
<td>{{service}}</td>
<td>{{status}}</td>
<td> <button class="btn-success" id="try" value="Deactivate" onClick="Reactivate()" name="status">Reactivate</button></tr>
{% endfor %}
</tbody>
</table>
</form>
</div>
</div>
<!-- The Modal -->
<div id="modal01" class="modal" onclick="this.style.display='none'">
<span class="close">× </span>
<div class="modal-content">
<img id="img01" style="max-width:100%">
</div>
</div>
{% endblock %}
my view.py
def deactivate_status(request):
all_ids =
db.child('Users').child('AllServiceProviders').shallow().get().val()
StatusIds = []
for status_id in all_ids:
StatusIds.append(status_id)
AccStatus = []
for i in StatusIds:
accstate = db.child('Users').child('AllServiceProviders').shallow().child(i).child('accountStatus').get()
accstate = accstate.val()
if accstate=='approved':
data={"accountStatus":"deactivated"}
dat=db.child('Users').child('AllServiceProviders').child(i).update(data)
AccStatus.append(dat)
return redirect('index')
这是我试图用来更新 Firebase 的 javascript
<script>
var config ={<!-- this is the configuration script that connects to
the firebase-->
'apiKey': "XXXXXXXXXXXXXXXXXXXXX",
'authDomain': "XXXXXXXXXXXXXXXXXXXXX",
'databaseURL': "XXXXXXXXXXXXXXXXXXXXXXXXXXX",
'projectId': "canondashoard",
'storageBucket': "XXXXXXXXXXXXXXXXXXXXXX",
'messagingSenderId': "XXXXXXXXXXXXXXXXXXXXXXXXXX",
'appId': "XXXXXXXXXXXXXXXXXXXXXXXXX"
};
firebase.initializeApp(config);
function Reactivate() {
var database = firebase.database();
var stateref=database.ref().child('Users').child('AllServiceProviders');
var key = stateref.push().key;
var update ={};
update[key]={accountStatus:'approved'};
var result=stateref.update(update);
document.getElementById('try').innerHTML='result:'+result;
}
我没有向您展示我的 firebase-real-time-database,因为它工作正常,我想在按下停用按钮时更新单个节点 ID,但不要一次更新所有节点。
谢谢你的帮助。
我通过将 firebase Django 更改为 nodejs 并将其连接到 firebase 解决了这个问题,这使得使用 jQuery 进行数据检索变得非常容易和引人入胜,而不是使用 Django 调用 firebase。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.