Comments (5)
@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.
@ssfdust django的forms模块设计结合模板来用很高效的,而我们现在已经摒弃后端模板渲染这种方式,变成前后端分离了,forms模板的部分功能比如validate之类应该也可以用吧,你多看看文档,比如:
application/x-www-form-urlencoded
是什么原理,
- 如何使用django的form类
- 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.
如果用django rest framework 写的api,前端post表单的时候crsftoken怎么解决呢?
from django-with-vuejs.
@hchen1202 #3
from django-with-vuejs.
问题已经解决。谢谢。
from django-with-vuejs.
Related Issues (17)
- 按照教程设置了,但是提示找不到静态文件怎么办。 HOT 1
- 有没有更加复一点的项目代码? HOT 2
- 项目完整版源码 HOT 6
- how to handle django login page from vuejs ? HOT 2
- 請教下下目錄問題 HOT 2
- 啥反应也没有.. 浏览器也没报错 HOT 3
- backend HOT 1
- python: can't open file 'manage': [Errno 2] No such file or directory HOT 3
- 代码和知乎专栏里的代码不一样,以哪个为准? HOT 3
- where is the vuejs part
- 跨域问题 HOT 1
- django的model如何应用? HOT 1
- 设置 STATICFILED_DIRS 仍然找不到静态文件 HOT 1
- npm run build 出错 HOT 1
- <div id="app">不会自动注入 HOT 2
- Cannot find module 'D:\code\vue\django-with-vuejs\my_project\frontend\build\build.js' HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from django-with-vuejs.