Giter Club home page Giter Club logo

Comments (5)

tmpbook avatar tmpbook commented on July 19, 2024 2

@hchen1202 @ssfdust
Django 提供了一段js来生成csrftoken,你可以生成然后加到表单中,比禁用掉更完美,我找找:

// using jQuery
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;
}
var csrftoken = getCookie('csrftoken');

地址

from django-with-vuejs.

tmpbook avatar tmpbook commented on July 19, 2024

@ssfdust django的forms模块设计结合模板来用很高效的,而我们现在已经摒弃后端模板渲染这种方式,变成前后端分离了,forms模板的部分功能比如validate之类应该也可以用吧,你多看看文档,比如:
application/x-www-form-urlencoded是什么原理,

  1. 如何使用django的form类
  2. https://docs.djangoproject.com/en/1.11/ref/forms/api/
>>> data = {'subject': 'hello',
...         'message': 'Hi there',
...         'sender': '[email protected]',
...         'cc_myself': True}
>>> f = ContactForm(data)

from django-with-vuejs.

TrinityHC avatar TrinityHC commented on July 19, 2024

如果用django rest framework 写的api,前端post表单的时候crsftoken怎么解决呢?

from django-with-vuejs.

ssfdust avatar ssfdust commented on July 19, 2024

@hchen1202 #3

from django-with-vuejs.

ssfdust avatar ssfdust commented on July 19, 2024

问题已经解决。谢谢。

from django-with-vuejs.

Related Issues (17)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.