我如何使用 Elasticsearch 从 Django 的前端获取 edit/delete 数据?
How do i edit/delete data from the frontend in Django with Elasticsearch?
我想从我的后端 (postgresql) 检索数据到前端,这样我就可以 edit/delete 它了。
注意:我的项目正在使用django_elasticsearch_dsl_drf
我已经在 views.py 中实现了这个:
def update(request, id):
resp = Response.objects.get(pk = id)
resp.response = request.POST.get('Response')
resp.save()
return render(request, 'app/update', {
})
urls.py:
url(r'update/(\d+)/$', views.update, name="update")
如何在我的表单中显示它?
update.html:
<table class="dataTable">
{% for field in qform.visible_fields %}
<tr>
<th>{{ field.label_tag }}*</th>
<td>{{ field }}</td>
</tr>
{% endfor %}
<tr>
<th>{{ rform.Response.label_tag }}*</th>
<td>{{ rform.Response }}</td>
</tr>
<tr>
<th>{{ rform.Topic.label_tag }}*</th>
<td>{{ rform.Topic }}</td>
</tr>
<tr>
<th>{{ rform.Client.label_tag }}*</th>
<td>{{ rform.Client }}</td>
</tr>
<tr>
<th>{{ rform.Planit_location.label_tag }}*</th>
<td>{{ rform.Planit_location }}</td>
</tr>
<tr>
<th>{{ rform.Date_added.label_tag }}</th>
<td>{{ rform.Date_added }}</td>
</tr>
<tr>
<th>{{ rform.Document.label_tag }}</th>
<td>{{ rform.Document }}</td>
</tr>
此外,当我尝试访问 url .../update
时,我收到断言错误 "No exception message supplied"
编辑
堆栈跟踪:
Internal Server Error: /update/3/
django_1 | Traceback (most recent call last):
django_1 | File "/usr/local/lib/python3.6/site-packages/django/core/handlers/exception.py", line 35, in inner
django_1 | response = get_response(request)
django_1 | File "/usr/local/lib/python3.6/site-packages/django/core/handlers/base.py", line 128, in _get_response
django_1 | response = self.process_exception_by_middleware(e, request)
django_1 | File "/usr/local/lib/python3.6/site-packages/django/core/handlers/base.py", line 126, in _get_response
django_1 | response = wrapped_callback(request, *callback_args, **callback_kwargs)
django_1 | File "/app/app/views.py", line 358, in update
django_1 | "rform": resp,
django_1 | File "/usr/local/lib/python3.6/site-packages/django/shortcuts.py", line 36, in render
django_1 | content = loader.render_to_string(template_name, context, request, using=using)
django_1 | File "/usr/local/lib/python3.6/site-packages/django/template/loader.py", line 61, in render_to_string
django_1 | template = get_template(template_name, using=using)
django_1 | File "/usr/local/lib/python3.6/site-packages/django/template/loader.py", line 19, in get_template
django_1 | raise TemplateDoesNotExist(template_name, chain=chain)
django_1 | django.template.exceptions.TemplateDoesNotExist: app/update/
您的 url 路径应该是:
url(r'update/(?P<id>\d+)/$', views.update, name="update")
此外,您需要return更新方法中的内容:
return render(request, 'update_add.html', { 'rform': resp })
我想从我的后端 (postgresql) 检索数据到前端,这样我就可以 edit/delete 它了。
注意:我的项目正在使用django_elasticsearch_dsl_drf
我已经在 views.py 中实现了这个:
def update(request, id):
resp = Response.objects.get(pk = id)
resp.response = request.POST.get('Response')
resp.save()
return render(request, 'app/update', {
})
urls.py:
url(r'update/(\d+)/$', views.update, name="update")
如何在我的表单中显示它?
update.html:
<table class="dataTable">
{% for field in qform.visible_fields %}
<tr>
<th>{{ field.label_tag }}*</th>
<td>{{ field }}</td>
</tr>
{% endfor %}
<tr>
<th>{{ rform.Response.label_tag }}*</th>
<td>{{ rform.Response }}</td>
</tr>
<tr>
<th>{{ rform.Topic.label_tag }}*</th>
<td>{{ rform.Topic }}</td>
</tr>
<tr>
<th>{{ rform.Client.label_tag }}*</th>
<td>{{ rform.Client }}</td>
</tr>
<tr>
<th>{{ rform.Planit_location.label_tag }}*</th>
<td>{{ rform.Planit_location }}</td>
</tr>
<tr>
<th>{{ rform.Date_added.label_tag }}</th>
<td>{{ rform.Date_added }}</td>
</tr>
<tr>
<th>{{ rform.Document.label_tag }}</th>
<td>{{ rform.Document }}</td>
</tr>
此外,当我尝试访问 url .../update
时,我收到断言错误 "No exception message supplied"编辑 堆栈跟踪:
Internal Server Error: /update/3/
django_1 | Traceback (most recent call last):
django_1 | File "/usr/local/lib/python3.6/site-packages/django/core/handlers/exception.py", line 35, in inner
django_1 | response = get_response(request)
django_1 | File "/usr/local/lib/python3.6/site-packages/django/core/handlers/base.py", line 128, in _get_response
django_1 | response = self.process_exception_by_middleware(e, request)
django_1 | File "/usr/local/lib/python3.6/site-packages/django/core/handlers/base.py", line 126, in _get_response
django_1 | response = wrapped_callback(request, *callback_args, **callback_kwargs)
django_1 | File "/app/app/views.py", line 358, in update
django_1 | "rform": resp,
django_1 | File "/usr/local/lib/python3.6/site-packages/django/shortcuts.py", line 36, in render
django_1 | content = loader.render_to_string(template_name, context, request, using=using)
django_1 | File "/usr/local/lib/python3.6/site-packages/django/template/loader.py", line 61, in render_to_string
django_1 | template = get_template(template_name, using=using)
django_1 | File "/usr/local/lib/python3.6/site-packages/django/template/loader.py", line 19, in get_template
django_1 | raise TemplateDoesNotExist(template_name, chain=chain)
django_1 | django.template.exceptions.TemplateDoesNotExist: app/update/
您的 url 路径应该是:
url(r'update/(?P<id>\d+)/$', views.update, name="update")
此外,您需要return更新方法中的内容:
return render(request, 'update_add.html', { 'rform': resp })