Forms page doesn't render properly and data typed aren't saved

I psoted a similar question about a month ago. I went to work on ohter parts of the project, get a good answer to my question, but could not resolve. So I though would be better do another topic.

The page is rendering tokens and tagas as text, like csrf an if else are being displayed on screen. The other problem is that the form data is not being saved at data base. I looked at the console, by browser inspection, and it returns:

   POST http://incluirvendedor/ net::ERR_NAME_NOT_RESOLVED

HTML:

{% extends 'index.html' %}
{% block content %}

<div ng-controller="PessoasController">
    <div class="row">
        <div class="col s12">
            <button type="button" class="btn waves-effect waves-light tool-pattern-btn btn-action-pattern"
                onclick="javascript:history.go(-1)"><i class="material-icons left">keyboard_return</i>Go Back</button>
        </div>

        <div class="col s12">
            {% if submitted %}
            Employee included succefully!
            {% else %}
            <form method="post">
                <div class="card hoverable">
                    {% csrf_token %}
                    <div class="card-content exib-pattern">
                        <span class="card-title-home"><i class="material-icons left">add</i>Add New Employee</span>
                        
                        <div class="row">
                            <div class="input-field col s12 l6">
                                <input ng-model="pessoa.name" maxlength="255" type="text" class="form-control" id="nome"
                                    name="nome" />
                                <label for="nome">Name:</label>
                            </div>
                            <div class="input-field col s12 l4">
                                <input ng-model="pessoa.identidade" maxlength="255" type="text" class="form-control"
                                    id="identidade" name="identidade" />
                                <label for="id">identidade:</label>
                            </div>
                        </div>
                        <div class="row">
                            <div class="input-field col s12 l3">
                                <input ng-model="pessoa.position" maxlength="50" type="text" class="form-control"
                                    id="position" name="position" />
                                <label for="id">Position:</label>
                            </div>
                            <div class="input-field col s12 l3">
                                <input ng-model="pessoa.store" maxlength="50" type="text" class="form-control" id="store"
                                name="store">
                                <label for="id">store:</label>
                            </div>
                        </div>
                        {{ form|crispy }}
                        <div class="row">
                            <div class="col s12">
                                <button ng-click="submitForm()" class="btn waves-effect waves-light tool-pattern-btn green">
                                    <i class="material-icons left">add</i>Add</button>
                            </div>
                        </div>

                    </div>
                </div>
            </form>
            {% endif %}
        </div>
    </div>
</div>
{% endblock %}

view:

def incluirVendedor(request):
    submitted = False
    if request.method == "POST":
        form = incluirForm(request.POST)
        if form.is_valid():
            form.save()
            return HttpResponseRedirect(reverse('incluirVendedor') + '?submitted=True')
    else:
        form = incluirForm()
        if 'submitted' in request.GET:
            submitted = True

    return render(request, 'pages/pessoas/incluir.html', {'form':form, 'submitted':submitted})

java script:

    $scope.submitForm = function(){
        $http({
            method: 'POST',
            url: '/incluir', 
            data: $scope.pessoa 
        }).then(function successCallback(response) {
            console.log("Data sent successfully");
        }, function errorCallback(response) {
            console.error("Error sending data");
        });
    }

Angular route:

$routeProvider.when("/incluirVendedor/form", {templateUrl: "static/pages/pessoas/incluir.html", controller: "PessoasController"});

url path:

path('incluir', pessoas.incluirVendedor, name='incluirVendedor'),

That is an invalid url, because you’re not identifying the host. A proper url would more look like http://www.mysite.com/incluirvendedor/

If that URL is being generated by some JavaScript, then this is a JavaScript issue and not a Django issue.

The thing is, I am running it locally. I didn’t redirect to this url, at least I think I didn’t any direciton for this

on terminal, the answer is this, everytime i hit save button:

[06/Mar/2024 14:32:45] "POST /home HTTP/1.1" 200 9755
[06/Mar/2024 14:32:45] "GET /static/pages/pessoas/incluir.html HTTP/1.1" 304 0
Not Found: /favicon.ico
[06/Mar/2024 14:34:03] "GET /favicon.ico HTTP/1.1" 404 9465
[06/Mar/2024 14:41:46] "POST /home HTTP/1.1" 200 9755
Not Found: /favicon.ico
[06/Mar/2024 14:45:53] "GET /favicon.ico HTTP/1.1" 404 9465

If you’re showing this error in the browser:

then you’re not going to see the requests on the server. The request is not leaving the browser because the browser doesn’t know where to send the request.

Whatever this is, it has nothing to do with anything you’re seeing on the server. This error is strictly a browser / JavaScript issue and is not a Django issue.

However, I do see where you are posting to “/home”. What view is this and what is it doing?

I think the problem is with the template, it is on static/pages/template.html, and angular is trying to run it on templates folder. The /home, is the index on that folder, the index general.

“Angular” does not run templates, unless you’re referring to something other than a Django template here - in which case there’s a terminology mismatch involved.

Django renders templates to become HTML on the server, then sends that HTML to the browser. (Note, Django templates do not belong in the static directory. A Django template belongs in the templates directory.)

Angular is JavaScript that runs in the browser. It has nothing to do with Django or its templates.

Question: How much experience do you have with Angular? How much with Django?

None. It’s my first work on it and its an academical work, I am implementing it. Anyaway, thanks, I will try with my professors.

I suggest then you don’t try to combine these two until you gain some experience with both independently. This is a large learning curve to start with, and you’re going to need a very solid understanding of Django before you can expect to be able to get Angular working with it.