为了账号安全,请及时绑定邮箱和手机立即绑定

如何使用超链接更改 Django 中的实例?

如何使用超链接更改 Django 中的实例?

海绵宝宝撒 2021-11-09 10:56:23
我有 Django 的问题。我想使用超链接更改模型的特定字段,但我不知道该怎么做。我试过这个,但它什么也没做。视图.py:def sGiocatore(request, giocatore_id):    item = get_object_or_404(Giocatore, pk=giocatore_id)    item.fantasquadra=None #or something else    return redirect('/sondaggio/fantasquadre')网址.py:path('svincola/<int:giocatore_id>/', views.sGiocatore, name='s_player'),表格.py:class EditGiocatoreForm(forms.ModelForm):class Meta:    model = Giocatore    fields = ['fantasquadra']列表.html:{% for fantasquadra in elenco_fantasquadre %}<p><b>{{ fantasquadra.nome_fantasquadra }}:</b></p><table id="customers">{%for giocatore in elenco_giocatori%}{% if giocatore.fantasquadra.nome_fantasquadra == fantasquadra.nome_fantasquadra %}<tr><th>Nome</th><th>Cognome</th><th>N° Maglia</th><th>Squadra</th> <th>Ruolo</th><th>Svincola</th></tr><tr><td>{{ giocatore.nome_giocatore }}</td><td>{{ giocatore.cognome_giocatore }}</td><td>{{giocatore.numero_maglia}}</td><td>{{giocatore.squadra.nome_squadra}}</td><td>{{giocatore.ruolo.ruolo}}</td><td><a href="/sondaggio/svincola/{{giocatore.id}}">Svincola</a></td></tr> {% endif %}{% endfor %}</table>  {% endfor %}
查看完整描述

1 回答

?
犯罪嫌疑人X

TA贡献2080条经验 获得超4个赞

item.save()修改后添加。


查看完整回答
反对 回复 2021-11-09
  • 1 回答
  • 0 关注
  • 173 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号