在DRF服务器上,授权API工作正常(我使用jwt)。但是当我尝试从 React 中执行相同操作时,我收到消息 Cannot POST /login。服务器上没有关于post请求的信息,即问题出在前端。
const Login = () => {
const [username, setUsername] = useState('');
const [password, setPassword] = useState('');
const [error, setError] = useState('');
const loginUser = async () => {
try {
const response = await axios.post('http://127.0.0.1:8000/api/v1/token/', { username, password });
localStorage.setItem('access', response.data.access);
localStorage.setItem('refresh', response.data.refresh);
setError('');
} catch (err) {
setError(err.response.data.message);
}
};
return (
<div>
<form class="form_auth_style" method="post">
<div class="form-group">
<input class="form-control item" type="text" name="username" placeholder="Логин" required />
</div>
<div class="form-group">
<input class="form-control item" type="password" name="password" placeholder="Пароль" required />
</div>
<div class="form-group">
<button class="btn btn-primary btn-block create-account" type="submit">Вход в аккаунт</button>
</div>
</form>
</div>
);
};
export default Login;