在djang中编辑从数据库检索的数据

2024-09-29 17:20:36 发布

您现在位置:Python中文网/ 问答频道 /正文

我已经从数据库中检索到数据并将其显示在表中。 现在单击编辑按钮,我想编辑表。下面是我的代码。但什么也没发生。我无法编辑内容。没有得到任何错误。 我是个新手。Plzz帮助。。在

我的视图.py文件

def editquestiondata(request, id):
    info = Trans.objects.get(pk = id)
    info.transtype_id = request.POST.get('editexplain')
    info.save()
    return HttpResponse('updated')

我的网址.py文件

^{pr2}$

HTML模板

<table border="1" style="width:800px">
<button type="button" value="Edit explain" name="editexplain">Edit</button>
<button type="button" onclick="alert('Changes Saved!')">Save</button>
<tr>
  {% for s in questdata %} 
</tr>
<tr>
<td>   {{ s.script }} </td>
<td>   {{ s.id }} </td>
</tr>    

  {% endfor %} 

</table>

Tags: 文件pyinfoid数据库编辑getrequest
1条回答
网友
1楼 · 发布于 2024-09-29 17:20:36

找到答案了。。。在

我的HTML模板

enter code here

<!doctype html>
<html>
<body>
<table border="1" style="width:900px">

<tr>
   {% for s in details %} 
</tr>
<form action=" " method="POST">
<input type="hidden" value={{ s.id }} name="sid" />
<tr>
<td>   
       {{ s.script }}
  {% if s.id == sid %}
        <input type="text" name="script" value="{{ s.script }}" />

  {% endif %}
</td>

<td> <a href="/accounts/newexplain/?sid={{ s.id }}">Edit</a> </td>

</form>
</tr>    

  {% endfor %} 

</table>
</body>
</html>

我的视图.py文件

^{pr2}$

相关问题 更多 >

    热门问题