在django 2.2中从data-url获取ID时出现的问题

问题描述 投票:1回答:1

这是我的脚本:

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 ...

python django django-forms bootstrap-modal django-2.2
1个回答
1
投票

您将path(..) [Django-doc]语法与path(..)语法混合在一起。 re_path(..) [Django-doc]语法不使用正则表达式,但使用路径转换器。


-5
投票

urlpatterns = [ path('details/<int:pk>/', views.index, name='details'), # … ]/details/(?P4\d)

© www.soinside.com 2019 - 2024. All rights reserved.