这是我的脚本:
views.py
from profil.models import dayah
def index(request):
dayah = profil_dayah.objects.all
return render(request,'index.html', { 'dayah' : dayah })
index.html
{% for dayahs in dayah %}
<button type="button" class="btn btn-primary see-details" data-toggle="modal" data-target="#exampleModalLong" data-url="{% url 'details' dayahs.id %}">Detail</button>
{% endfor %}
get_id.js
$(".see-details").on('click', function (){
var url = $(this).data('url')
console.log(url);
})
console.log的结果应该是
/details/1
int 1是{{dayahs.id}}的ID但我的实际结果是:
/details/(%3FP4%5Cd/)
为什么这样的结果?我希望结果是console.log中的/ details / 1]
这是我的脚本:profil.models中的views.py导入dayah def index(request):dayah = profil_dayah.objects.all返回render(request,'index.html',{'dayah':dayah})索引。 html {%for Dayahs ...
您将path(..)
[Django-doc]语法与path(..)
语法混合在一起。 re_path(..)
[Django-doc]语法不使用正则表达式,但使用路径转换器。
urlpatterns = [
path('details/<int:pk>/', views.index, name='details'),
# …
]
/details/(?P4\d)