Я использую django с начальной загрузкой, где у меня есть модал, включающий вкладки в качестве ссылок, где каждая вкладка запускает функцию и возвращает необходимые данные.
Проблема в том, что одна из этих вкладок не работает .. ... но если я уберу эту вкладку и использую ее как кнопку, функция сработает и вернет правильные значения.
Обратите внимание, что первые 2 вкладки запускают ту же функцию, а третья - другую функцию.
views.py
def search(request):
# search for person
query = request.GET.get('search')
print('query===>',query)
try:
if query != "":
print("query is not empty!")
try:
c = cursor.execute('SELECT Person_.ID,Person_.Full_Name,Person_.Mothers_Name,Person_.Nickname_,Person_.Details,Person_.Address_,Person_.preferedActivity,Person_.Other_Activity,Person_.Other_Descriptive_Details,Person_.Status, Person_.Date_of_Birth,Person_.Place_of_Birth FROM Person_ WHERE Person_.ID LIKE ? or Person_.Full_Name LIKE ? or Person_.Mothers_Name like ? or Person_.Nickname_ LIKE ? or Person_.Details LIKE ? ORDER BY Person_.ID DESC',('%' + query + '%' ,'%' + query + '%', '%' + query + '%', '%' + query + '%', '%' + query + '%'))
cc = c.fetchall()
paginator = Paginator(cc,20)
page_request_var = "page"
print("page_request_var===>",page_request_var)
page = request.GET.get(page_request_var)
print("page====>",page)
queryset = paginator.get_page(page)
print("queryset=====>",queryset)
return render(request,'pictureCard.html', {'c': cc,'countID':countID,
'countFullName': countFullName,
'countMother': countMother,
'countNickname':countNickname,
'countCritical':countCritical,
"object_list":queryset,
"page_request_var":page_request_var,
})
else:
print("Search value is empty")
return redirect('../../')
except pyodbc.DataError:
print("DataError: Invalid value!")
return redirect('../../')
def getEvents(request,id):
# search for person
print("Entered Person getEvents Function!")
q1 = cursor.execute('SELECT Person_.ID FROM Person_ WHERE Person_.ID = {0}'.format(id))
print('q1==>',q1)
print("query is not empty!")
eventQ = cursor.execute('SELECT Person_.ID, Person_.Full_Name, Events.ID, Events.Event_Title, Events.Event_Details, Links.document_id from Person_, Events, Links where ( Person_.ID = {0}) and (Person_.ID = Links.A_Person or Person_.ID = Links.B_Person) and (Events.ID = Links.A_Event or Events.ID = Links.B_Event) ORDER BY Events.ID DESC '.format(id))
resultEvents = eventQ.fetchall()
return render(request,'pictureCard.html',{
"resultEvents":resultEvents,
})
pictureCrads.html
<!-- Popup Modal -->
{% for obj in object_list %}
<div id="popModel{{obj.0}}" class="modal fade modal-rtl" role="dialog">
<div class="modal-dialog modal-lg">
<!-- Modal content-->
<div class="modal-content">
<div class="modal-header Modal-Pic">
<button type="button" class="close" data-dismiss="modal">×</button>
<h4 class="modal-title">{{ obj.1 }}</h4>
<a href="{% static 'img/logo_title/icon-AddressBar.png' %}" data-toggle="modal" data-target="#test2"><img src="{% static '/img/card/1.png'%}"/></a>
</div>
<!-- tabs inside modal -->
*******here is the tabs
<ul class="nav nav-tabs" id="myTab" role="tablist">
<li class="nav-item">
<a class="nav-link active" id="home-tab" data-toggle="tab" data-target="home{{ obj.0 }}" href="#home{{ obj.0 }}" role="tab" aria-controls="home" aria-selected="true">preferred activities</a>
</li>
<li class="nav-item">
<a class="nav-link" id="profile-tab" data-toggle="tab" data-target="profile{{ obj.0 }}" href="#profile{{ obj.0 }}" role="tab" aria-controls="profile" aria-selected="false">other activities</a>
</li>
<li class="nav-item">
<a class="nav-link" id="contact-tab" data-toggle="tab" data-target="contact{{ obj.0 }}" href="#contact{{ obj.0 }}" role="tab" aria-controls="contact" aria-selected="false">status</a>
</li>
*****here is the error this tab doesn't work.
<li class="nav-item">
<a class="nav-link" id="event-tab" data-toggle="tab" data-target="event{{ obj.0 }}" href="{% url 'getEvents' obj.0 %}" role="tab" aria-controls="event" aria-selected="false">events</a>
</li>
<li class="nav-item mr-auto btn-warning">
<a class="nav-link text-dark" id="contact-tab" data-toggle="tab" href="#picture" role="tab" aria-controls="contact" aria-selected="false">Picture</a>
</li>
</ul>
<!-- tabs contents inside modal -->
<div class="modal-body tab-content" id="myTabContent">
<div class="tab-pane fade show active" id="home{{ obj.0 }}" role="tabpanel" aria-labelledby="home-tab">{{ obj.7 }}</div>
<div class="tab-pane fade" id="profile{{ obj.0 }}" role="tabpanel" aria-labelledby="profile-tab">{{ obj.8 }}</div>
<div class="tab-pane fade" id="contact{{ obj.0 }}" role="tabpanel" aria-labelledby="contact-tab">{{ obj.9 }}</div>
*********this is where must run the second function and return the data
{% for event in resultEvents %}
<div class="tab-pane fade" id="event{{ obj.0 }}" role="tabpanel" aria-labelledby="event-tab">
<button class="btn btn-primary" > events </button>
{{ event.2 }} # this must return the name of the person.
</div>
{% endfor %}
<div class="tab-pane fade" id="picture" role="tabpanel" aria-labelledby="contact-tab">
<a class="" href="#"><img class="" src="{% static '/img/card/noPhotoAvailable.png'%}"/></a>
</div>
</div>
</div>
</div>
</div>
{% endfor %}
......
<footer class="card-footer card-footer-buttom text-center bg-info">
<form method="GET" action="{% url 'getEvents' obj.0 %}">
<a href="#" type="button" id="btnfooter" class="btn btn-primary" data-toggle="modal" data-target="#popModel{{obj.0}}">details</a>
****if click the button it works correctly
<button class="btn btn-primary" > details as button </button>
</form>
</footer>