看起来已经有很多关于此的讨论,但我无法让我的代码工作。
我有一个Django项目和带有Bootstrap tab药片的模板。我试图将标签菜单药片绑定到我的Django项目的网址。我无法在客户端读取Uncaught Error: Syntax error, unrecognized expression: /employee_user_info/40/
错误。这是我的代码:
HTML:
<div class="container">
<h2>{{person_details_form.second_nm_rus.value}} {{person_details_form.first_nm_rus.value}} {{person_details_form.middle_nm_rus.value}}</h2>
<ul class="nav nav-pills">
<li class="active"><a data-toggle="pill" href="#home">Tab 1</a></li>
<li><a data-toggle="pill" href='/employee_user_info/{{employee_unique_id}}/'>Tab 2</a></li>
<li><a data-toggle="pill" href="#menu2">Tab 3</a></li>
</ul>
<div class="tab-content" style="margin-top:2%">
<div id="home" class="tab-pane fade in active">
<div class="container">
<!-- Something -->
</div>
</div>
</div>
Django urlconf
url(r'^employee_user_info/(?P<employee_unique_id>\d+)/$',employee_views.profile_user_info, name ='employee_user_info'),
JS
var navpills = $('.nav-pills');
$(function () {
// activate tab on click
navpills.on('click', 'a', function (e) {
var $this = $(this);
// prevent the Default behavior
e.preventDefault();
// send the hash to the address bar
window.location.hash = $this.attr('href');
// activate the clicked tab
$this.tab('show'); // The error arises here
});
$(window).bind('hashchange', refreshHash);
// read has from address bar and show it
if(window.location.hash) {
// show tab on load
refreshHash();
}
});
function refreshHash() {
navpills.find('a[href="'+window.location.hash+'"]').tab('show');
}
更新
当我点击标签2
时,客户端会发生错误更新2
按Tab 2时,网址变为http://127.0.0.1:8000/employee_profile_main/40/#/employee_user_info/40/
我想,降压就停在这里
答案 0 :(得分:0)
您无法使用href
为a
设置/
。我猜它用作选择器。