Hi Ronald, I don't think you are quoting your data-url tag properly in the html form. If you notice, you are missing the closing quotation(") which causes the <span class...> to be added to the url.
Regards, On Sat, 9 May 2020 at 18:58, Ronald Kamulegeya < ronald.kamulegeya.2...@gmail.com> wrote: > Hello Members. > > I am a django beginner and i am going trough online tutorials. > > I have the following view functions: > > # Create your views here. > def save_tenant_form(request, form, template_name): > data = dict() > if request.method == 'POST': > if form.is_valid(): > form.save() > data['form_is_valid'] = True > tenants = Tenants.objects.all() > data['html_tenant_list'] = render_to_string( > 'rentals/tenant_partial_list.html', { > 'tenant_list': tenants > }) > else: > data['form_is_valid'] = False > context = {'form': form} > data['html_form'] = render_to_string(template_name, context, request= > request) > return JsonResponse(data) > > > > > def createTenant(request): > if request.method == 'POST': > form = TenantsForm(request.POST) > else: > form = TenantsForm() > > return save_tenant_form(request, form, > 'rentals/partial_tenant_create.html') > > Here is the url for the create function > path("tenants/add/",views.createTenant, name='createTenant'), > > There is some java script to load the modal form shown below: > $(function () { > > > /* Functions */ > > > var loadForm = function () { > var btn = $(this); > $.ajax({ > url: btn.attr("data-url"), > type: 'get', > dataType: 'json', > beforeSend: function () { > $("#modal-tenant .modal-content").html(""); > $("#modal-tenant").modal("show"); > }, > success: function (data) { > $("#modal-tenant .modal-content").html(data.html_form); > } > }); > }; > > > var saveForm = function () { > var form = $(this); > $.ajax({ > url: form.attr("action"), > data: form.serialize(), > type: form.attr("method"), > dataType: 'json', > success: function (data) { > if (data.form_is_valid) { > $("#tenant-table tbody").html(data.html_book_list); > $("#modal-tenant").modal("hide"); > } > else { > $("#modal-tenant .modal-content").html(data.html_form); > } > } > }); > return false; > }; > > > > > /* Binding */ > > > // Create tenant > $(".js-create-tenant").click(loadForm); > $("#modal-tenant").on("submit", ".js-tenant-create-form", saveForm); > > In the html form, i try to load the modal form by clicking on this button > <p> > <button type="button" class="btn btn-primary js-create-tenant" > data-url="{% url 'rentals:createTenant' %}> > <span class="glyphicon glyphicon-plus"></span> > New Tenant > </button> > > </p> > I get a strange response shown below > [09/May/2020 11:38:58] "GET > /tenants/add/%3E%20%20%20%20%20%20%3Cspan%20class= HTTP/1.1" 404 2789 > > I need the "GET /tenants/add/ part only. I do not know how the additional > data is added to the Get request! > Any bug in my code causing the strange data to be added? > > Ronald > > -- > You received this message because you are subscribed to the Google Groups > "Django users" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to django-users+unsubscr...@googlegroups.com. > To view this discussion on the web visit > https://groups.google.com/d/msgid/django-users/2c8f5ac8-2109-49b4-ad8a-d75c2350a21c%40googlegroups.com > <https://groups.google.com/d/msgid/django-users/2c8f5ac8-2109-49b4-ad8a-d75c2350a21c%40googlegroups.com?utm_medium=email&utm_source=footer> > . > -- You received this message because you are subscribed to the Google Groups "Django users" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAFbbBpa6VPmaL%2BPEAHwKWWKdX2GxZyBR7rfc1cPviEq4yop-dQ%40mail.gmail.com.