我试着理解你的问题,我会用我的Django web应用程序的例子来回答。
在我的情况,但你的是类似的,我有一个模板,从我的数据库呈现在一个表中的所有公司。我显示所有公司,如果我点击一个单元格,我可以根据这家公司咨询一个包含所有信息的新模板。这是你要求的完全相同的问题。
第一步:
from django.conf.urls import url
from . import views
urlpatterns = [
url(r'^Formulaire/Societes$', views.Identity_Societe_Form, name = "SocieteFormulaire"),
url(r'^Resume/Societes$', views.Identity_Societe_Resume, name = "SocieteResume"),
url(r'^Contrat/Societe/(?P<id>\d+)/$', views.Identity_Contrat, name="Contrat"),
]
SocieteFormulaire
让填写表格并保存对象:urls.py文件 在这个文件中,我根据你的问题有3个网址我的数据库
SocieteResume
让我们可以在一个表中显示所有公司的多个信息。在此表中,我可以点击里面以显示公司模板。 Contrat
让在已选定公司的功能,显示模板
第二步:与恢复功能view.py文件
在我看来,我有让里面显示所有公司的功能一个HTML模板。
@login_required
def Identity_Societe_Resume(request) :
societe = Societe.objects.all()
contrat = SocieteContrat.objects.all()
paginator = Paginator(societe, 10)
page = request.GET.get('page', 1)
try:
societe = paginator.page(page)
except PageNotAnInteger:
societe = paginator.page(1)
except EmptyPage:
societe = paginator.page(paginator.num_pages)
paginator = Paginator(contrat, 10)
page = request.GET.get('page', 1)
try:
contrat = paginator.page(page)
except PageNotAnInteger:
contrat = paginator.page(1)
except EmptyPage:
contrat = paginator.page(paginator.num_pages)
context={
"societe" : societe,
"PageNotAnInteger":PageNotAnInteger,
"contrat" : contrat,
}
return render(request, 'Identity_Societe_Resume.html', context)
我显示我的数据库名为该HTML模板注册的所有企业:Identity_Societe_Resume.html
此模板的核心是这样的:
<h4><b> <span class="glyphicon glyphicon-user"></span></span> Récapitulatif des Sociétés ayant souscrit à un contrat de services : </b></h4>
<table style="width:125%">
<tbody>
<tr>
<th>ID</th>
<th>Nom</th>
<th>État</th>
<th>SIRET</th>
<th>SIREN</th>
<th>NAF-APE</th>
<th>Adresse</th>
<th>Ville</th>
<th>Pays</th>
</tr>
{% for item in societe %}
<tr>
<td><a href="http://localhost:8000/Identity/Contrat/Societe/{{item.id}}"> Ici </a></td>
<td>{{ item.Nom}}</td>
<td>{{ item.Etat}}</td>
<td>{{ item.SIRET }}</td>
<td>{{ item.SIREN }}</td>
<td>{{ item.NAF_APE }}</td>
<td>{{ item.Adresse }}</td>
<td>{{ item.Ville}}</td>
<td>{{ item.Pays.name }}</td>
</tr>
{% endfor %}
</tbody>
</table>
正如你看到的,我的表显示一些信息并显示company ID
。但是,根据前面显示的urls.py
文件,此信息是公司模板的链接。
第三步:与公司信息
在这一步views.py文件,我根据好公司显示信息。 在我的网址,我有:http://localhost:8000/Identity.Contrat/Societe/1
数1
显示信息约company 1
然后,我有我的观点:
@login_required
def Identity_Contrat(request, id) :
societe = get_object_or_404(Societe, pk=id)
contrat = get_object_or_404(SocieteContrat, pk=id)
#etc ...
有这真的很重要:(request, id)
并在每个查询集我提到约company ID
最后,在我的模板中我有:
<h4><b> Récapitulatif concernant la société : {{societe.Nom}}</b></h4>
<table style="width:125%">
<tbody>
<tr>
<th>ID</th>
<th>Nom</th>
<th>État</th>
<th>SIRET</th>
<th>SIREN</th>
<th>NAF-APE</th>
<th>Adresse</th>
<th>Ville</th>
<th>Pays</th>
</tr>
<tr>
<td>{{societe.id}}</td>
<td>{{ societe.Nom}}</td>
<td>{{ societe.Etat}}</td>
<td>{{ societe.SIRET }}</td>
<td>{{ societe.SIREN }}</td>
<td>{{ societe.NAF_APE }}</td>
<td>{{ societe.Adresse }}</td>
<td>{{ societe.Ville}}</td>
<td>{{ societe.Pays.name }}</td>
</tr>
</tbody>
</table>
希望这个例子是有益的,我的英语这是很闹心我很抱歉..
如果我的回答解决你的问题,你能接受吗? ;) – Deadpool