我想弄清楚如何将原始字段数据及其结果发布到我的结果页面。我有一个用Django编写的应用程序,它有两个html页面。输入页面和结果页面。输入页面有一个表单。结果页面有输出。下面是我在的地方代码:Django参考原始文章数据
models.py
class IssuingCA (models.Model):
ICA_name = models.CharField(max_length=200)
filepath = models.CharField(max_length=200)
def __str__(self):
return self.ICA_name
views.py(简体版)
def index(request):
issuers = IssuingCA.objects.order_by('ICA_name')
issuerOptions = {'issuers': issuers}
return render(request, 'index.html', issuerOptions)
def results(request):
issuer = request.POST['selectedIssuer']
issuername = 'Where I want the ICA_name value "icas" displayed'
info = {'issuer': issuer, 'issuername': issuername}
return render(request, 'results.html', info)
的index.html
--snip--
<label for="selectedIssuers">Issuing CA</label>
<select id="selectedIssuers" name="selectedIssuers">
{% for icas in issuers %}
<option value="{{ icas.filepath }}">{{ icas }}</option>
{% endfor %}
--snip--
results.html
--snip--
<div>{{ issuer }}</div>
<div>{{ issuername }}</div>
--snip--
让我们为DB设置一些示例数据: ICA_Name =“squirrels”;文件路径=“在/某些/森林”
应用程序的工作方式是,它提出了一个下降,显示所有值的ICA_name
index.html页面了。当您选择ICA_name
(在这种情况下为“松鼠”并提交时,它会传递松鼠的filepath
选项的值 - “in/some/forest”,我通过POST请求并显示在结果页面上。我想要的是一种方法,也显示在结果页面上的松鼠,原来的价值,从而为issuer
,在<div>
文本显示松鼠(这个目前工程)和IssuerName
,在<div>
文本显示在/ some/forest。
嗯..我从来没有想过使用pk值和引用字段。我也不知道你可以写{issuer':issued_ca.filepath}。你教过我一些新的东西!我刚刚测试过它,它的工作原理!谢谢!我已经查看了以前的表单,并且打算更新我的应用程序以在将来的版本中使用它们。 – Eddi
尽快完成,不要等待。即使不是用于安全功能,也可以节省大量时间,特别是在维护/扩展已经编写的代码时(它始终是主时钟库)。 –