我用DRF制作了API服务器,所以如果删除数据,我必须使用DELETE方法。
所以我尝试用方法请求服务器:'DELETE',但它不起作用。
[js文件]
fetch("http://abc/article/24",
{
method: "DELETE",
headers: {
'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'
},
body: JSON.stringify({password: '123'})
})
Run Code Online (Sandbox Code Playgroud)
我使用 Chrome Network 选项卡捕获数据包,它的请求标头是 OPTION。
在我的代码中,我定义了 DELETE 方法。但是为什么Request Header的METHOD是OPTION呢?
[添加屏幕截图]
我设置了响应码如果成功返回204,失败返回304
当路由路径为“/flower”时,我想添加更多代码
所以我的代码如下。
[应用程序.js]
class App extends Component {
render() {
return (
<Router>
<div className="App">
<Header />
<SideBar />
<section>
<Route exact path="/" component={Home} />
<Route exact path="/flower" component={Flower} />
<Route exact path="/editorial" component={Editorial} />
</section>
<Footer />
</div>
</Router>
);
}
}
Run Code Online (Sandbox Code Playgroud)
[侧边栏.js]
import React, { Component } from 'react';
import './index.css';
import { NavLink } from 'react-router-dom';
class index extends Component {
render() {
return (
<aside>
<NavLink exact to="/" className="item"><i className="fas fa-home"></i>HOME</NavLink>
<NavLink to="/flower" className="item"><i className="fab fa-pagelines"></i>FLOWER</NavLink> …Run Code Online (Sandbox Code Playgroud) 我正在使用 django 和 mysql。
要与 mysql 通信 django,必须安装 mysqlclient。
另外python版本是3.7.2
pipenv install mysqlclient
它会引发错误。
Installing mysqlclient...
? Installation Succeeded
Pipfile.lock (c98c3a) out of date, updating to (a65489)...
Locking [dev-packages] dependencies...
Locking [packages] dependencies...
? Success!
Updated Pipfile.lock (c98c3a)!
Installing dependencies from Pipfile.lock (c98c3a)...
An error occurred while installing mysqlclient==1.4.2.post1 --hash=sha256:425e733b05e359a714d6007c0fc44582be66b63e5a3df0a50949274ae16f4bc6 --hash=sha256:62e4770b6a797b9416bcf70488365b7d6b9c9066878108499c559293bb464380 --hash=sha256:f257d250f2675d0ef99bd318906f3cfc05cef4a2f385ea695ff32a3f04b9f9a7! Will try again.
???????????????????????????????? 1/1 — 00:00:02
Installing initially failed dependencies...
[pipenv.exceptions.InstallError]: File "/usr/local/lib/python2.7/site-packages/pipenv/core.py", line 1992, in do_install
[pipenv.exceptions.InstallError]: skip_lock=skip_lock,
[pipenv.exceptions.InstallError]: File "/usr/local/lib/python2.7/site-packages/pipenv/core.py", line 1253, in do_init
[pipenv.exceptions.InstallError]: …Run Code Online (Sandbox Code Playgroud) 我在 python 中使用 mongodb。
也使用 MongoEngine 与 mongodb 进行通信。
现在我做了一些简单的具有评论功能的板系统。
[模型.py]
import datetime
from mongoengine import *
from config import DB_NAME
connect(DB_NAME)
class User(Document):
no = SequenceField()
userid = StringField(unique=True, required=True)
userpw = StringField(required=True)
created_at = DateTimeField(default=datetime.datetime.now())
class Comment(EmbeddedDocument):
content = StringField(required=True)
writer = ReferenceField(User, required=True)
class Board(Document):
no = SequenceField()
subject = StringField(required=True)
content = StringField(required=True)
writer = ReferenceField(User, required=True)
comments = ListField(EmbeddedDocumentField(Comment))
created_at = DateTimeField(default=datetime.datetime.now())
updated_at = DateTimeField(default=datetime.datetime.now())
Run Code Online (Sandbox Code Playgroud)
在此代码中,如何将新列表附加到Board的comments字段?
搜索了一个小时后,一些文件说,
Board.objects(no=_no).update_one(push__comments=['123', '456']) 将是完美的作品。
但它抛出 …
我用flask-restplus制作了API服务器。
还使用 cors 模块来避免 CSP 问题。
前端是 React.js。
我的代码在这里。
class ArticleList(Resource):
def post(self):
print(1)
return {"status":"true", "result":"article write success"}, 200
Run Code Online (Sandbox Code Playgroud)
React.js 代码在这里。
_writeArticle = () => {
const { title, body, tags, password } = this.state;
const data = {title: title, body: body, tags: tags, password: password};
fetch("http://127.0.0.1:5000/article/", {
method: "POST",
mode: "cors",
headers: {
"Content-Type": "application/json"
},
body: data
})
.then(res => {
if(res.status === 200) {
return <Redirect to='/' />
} else {
alert("error");
}
})
.catch(err => …Run Code Online (Sandbox Code Playgroud) 我是 ES6 的新手,所以我研究了 Javascript 的声明。
在测试 async/await 时,我发现了一些奇怪的行为。
我写了这样的代码,
const test = async () => {
await setTimeout(() => {
console.log("timeout");
}, 2000);
await console.log(1);
await console.log(2);
}
test();
Run Code Online (Sandbox Code Playgroud)
输出在这里,
1
2
timeout
[Finished in 2.1s]
Run Code Online (Sandbox Code Playgroud)
我将 async 定义为功能并等待每一行同步工作。
预期输出在这里,
timeout
1
2
[Finished in 2.1s]
Run Code Online (Sandbox Code Playgroud)
为什么这段代码不能同步?
谢谢。
我正在使用three.js进行图形化Web项目.
我有很多圈子,它像这样展开.
我想知道,如果物体和相机之间的距离越来越远,
对象的不透明度可以降低吗?(或淡出)
此外,如果距离越来越近,请将对象的不透明度设置为更高(或淡入)
我在docs(https://threejs.org/docs/index.html#manual/en/introduction/Creating-a-scene)中搜索过它,但没有明确的描述.
对此有什么解决方案吗?
谢谢.
reactjs ×3
javascript ×2
async-await ×1
cors ×1
ecmascript-6 ×1
fetch ×1
mongoengine ×1
pip ×1
pipenv ×1
python ×1
three.js ×1