H
H
howuu2019-02-05 14:46:24
Django
howuu, 2019-02-05 14:46:24

Want a custom form in Django? Am I doing the right thing?

I want the form for authorization to be like this
5c5975c37d0b6374477284.png
if I display the form in Django, it is like this I
5c5975dd5eff3074854720.png
thought how to do it simply, I do it this way
I use jQuery on the site
I will make such a js file so that
when you click on the login button, a post request is sent for authorization
Get csrf like this and send login and password like this

function getCookie(name) {
    var cookieValue = null;
    if (document.cookie && document.cookie !== '') {
        var cookies = document.cookie.split(';');
        for (var i = 0; i < cookies.length; i++) {
            var cookie = jQuery.trim(cookies[i]);
            // Does this cookie string begin with the name we want?
            if (cookie.substring(0, name.length + 1) === (name + '=')) {
                cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
                break;
            }
        }
    }
    return cookieValue;
}


function zapros() {

  var username  = $( ".username").val();
  var parol = $( ".password").val();


  
  var csrftoken = getCookie('csrftoken');
  data = {'csrfmiddlewaretoken':  csrftoken, username: username, password: parol };

  $.ajax({
          url: '/линк ту логин форм/',
          type: "POST",
          data: data 
        })  ;
  }

The question is, how correct is this in terms of everything, information security (how many hackers can hack us), beauty, work, or what do you advise to do? Because there are a lot of forms on the site and I want to do everything in this way

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question