我对HTML Django还是陌生的,并且我不知道合适的HTML术语,所以请忍受。
HTML文件的相关部分是这样的:
<select id="getAlignment" value2="" onchange="location = this.value;">
<option value="">Select an alignment</option>
{% for aln in some_Alignments %}
{%if 'LSU' not in aln.name%}
<option value2=getAlignment.value2 value="{% url 'alignments:detail' aln.name %}">{{ aln.name }}</option>
{% endif %}
{% endfor %}
</select>
value2的内容是使用Javascript分配的:
Vue.component('tree-menu', {
delimiters: ['[[',']]'],
template: '#tree-menu',
props: [ 'nodes', 'label', 'depth', 'taxID' ],
data() {
return {
showChildren: false
}
},
computed: {
iconClasses() {
return {
'fa-plus-square-o': !this.showChildren,
'fa-minus-square-o': this.showChildren
}
},
labelClasses() {
return { 'has-children': this.nodes }
},
indent() {
return { transform: `translate(${this.depth * 50}px)` }
}
},
methods: {
toggleChildren() {
this.showChildren = !this.showChildren;
// if (this.showChildren) {
var button = document.getElementById("getAlignment");
var newValue = this.taxID
button.setAttribute("value2", newValue);
// }
}
}
});
我想将value2的内容传递给Django,以用于选择适当的url。 相关的Django url架构如下:
from django.urls import include, path
from . import views
app_name = 'alignments'
urlpatterns = [
path('', views.index, name='index'),
path('rRNA/<str:name>/', views.rRNA, name='rRNA'),
path('rProtein/<str:align_name>/', views.detail, name='detail'),
path('showTaxonomy', views.buildTaxonomy, name='showTaxonomy'),
]
特别是views.detail是value2内容的目标目的地