简体   繁体   中英

How to solve page not found error in Django?

I have a list of multiple projects on my page, and each project have a contact use button, if a user click on contact us page then it will open a popup form, and I am doing this using Ajax. But whenever i click on the button it displays page not found in Network (After debug). Please let me know How I can solve thsi issue.

Here is my urls.py file...

re_path('ajax/datadis/<int:pk>/$', views.dataview, name='dataview'),

here is my views.py file...

def dataview(request, id):
    template_name = 'page/ajax/popup.html'
    return render(request, template_name)

here is my index.html file code...

<ul class="product-rating">
    <button title="Enquire for {{i.name}}" id="id_{{i.id}}" class="btn btn-primary btn-sm" onclick="projectDetail({{i.id}})" data-url="{% url 'appname:projectview' i.id %}">Contact Us</button>
</ul>

here is my Ajax Code...Which open the Popup Form...

</script>
function projectDetail(id){
var html = '';
var modalDiv = $("#modalData");
$.ajax({
url: "{% url 'appname:dataview' %}"+id,
type:"GET",
dataType:"HTML",
success: function(res) {
 modalDiv.html(res);
$("#exampleModal").modal("show");
 }
});
}
</script>

here is my popup model code...

<div class="modal fade" id="exampleModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalTitle" aria-hidden="true">
<div class="modal-dialog modal-dialog-centered" role="document">
  <div class="modal-content">
    <div class="modal-header">
      <h5 class="modal-title" id="exampleModalTitle">Modal title</h5>
      <button type="button" class="close" data-dismiss="modal" aria-label="Close">
        <span aria-hidden="true">&times;</span>
      </button>
    </div>
    <div class="modal-body" id="modalData">
      <p>{{i.name}}</p>
    </div>
    <div class="modal-footer">
      <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
      <button type="button" class="btn btn-primary">Save changes</button>
    </div>
  </div>
</div>

and this is the error which I am getting in console.

Page not found (404)    
Request URL:    http://127.0.0.1:8000/ajax/datadis/%3Cint:pk%3E/161

re_path has has a different syntax. it looks like path is sufficient for this url.

path('ajax/datadis/<int:pk>/', views.dataview, name='dataview'),

the url tag in the template will expect the id as a parameter.

{% url 'appname:dataview' id %}",

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM