Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

238
Visualizações
http://localhost:8000/token/ 400 (Bad Request)

in django, i have the jwt module for drf (it is called simple-jwt), and i have set up the urls as instructed in the docs, how do i fix the error, in backend side, the whole login process is supposed to be POST request: urls.py

urlpatterns = [
    path('token/', TokenObtainPairView.as_view(), name='token_obtain_pair'),
    path('token/refresh/', TokenRefreshView.as_view(), name='token_refresh'),

now for react part (frontend):

function Login(){
    let [login,setLogin] = useState({
        email: '',
        password:''

    });
    let cookie = Cookies.get('csrftoken');
    const { email, password } = login;
    function handleChange(e){
        console.log(e.target.value);
        setLogin({
            ...login,
            [e.target.name]: e.target.value
        });

    }
    function handleSubmit(e){
        const token = localStorage.getItem('token');
        e.preventDefault();
        axios.post('http://localhost:8000/token/',login,{withCredentials:true},{headers: {'Content-Type': 'application/json', 'X-CSRFToken': cookie,'Access-Control-Allow-Origin':'*','Authorization': `Bearer ${token}`}})
        .then(res => {
            console.log(res.data);
        }

        )
        .catch(err => console.log(err))
    }

    
    return (
        <div className="container">
        <form method='post' onSubmit={handleSubmit}>
            <h1>Login</h1>
            <label>
                Email:
                <input type='text' name = 'email' value={email} onChange={e=>handleChange(e)} required/>

            </label>
            <label>
                Password:
                <input type='password' name = 'password' value={password} onChange={e=>handleChange(e)} required/>
            </label>
            {isLoggedin = true}
            <button type='submit'>Login</button>
        </form>
            <p className='mt-3'>
                Don't have an Account? <Link to='/signup'>Sign Up</Link>
            </p>
        </div>
    );
};



export default Login;
``` this is login component, I am getting bad request (400) error, but I cant find out why, and how to fix it? if there is anything else (more code, or more information) to add, please do not be shy to tell me, thanks!
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

The Django 400 bad request is caused due to many reasons which include incorrect syntax, corrupt extensions, incorrect URL, and so on. You can try these steps :

  1. May be the ALLOWED_HOSTS variable is not set properly : be sure that ALLOWED_HOSTS = ['127.0.0.1', 'localhost'], since your are worked in local.

  2. Clearing the cache to fix 400 bad request error. The cache can also create problems, clear the cache and try checking if the error disappears.

  3. It's can also be caused by a corrupt extensions, then be aware about installed extensions you work with.

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda