我正在使用React创建注册页面,当前我正在使用
<Form action="https://xxxxx.amazonaws.com/production/accounts/register/" method="post">
这可行,但是它可以将我导航/重定向到django页面,有没有一种方法可以在没有导航/重定向的情况下进行设置?
我尝试使用<Form onSubmit={this.onSubmit}>
onSubmit = (event) => {
event.preventDefault();
fetch('https://xxxxxx.com/production/accounts/register/', {
credentials: 'include',
method: 'POST',
mode: 'no-cors',
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
'X-CSRFToken': csrftoken
},
body: JSON.stringify({
username: this.state.username,
email: this.state.email,
password1: this.state.password1,
password2: this.state.password2,
})
})
.then((result) => {
console.log("success");
})
.catch((error) => {
console.error(error);
});
}
但这不起作用。