Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

241
Views
http://localhost:8000/token/ 400 (solicitud incorrecta)

en django, tengo el módulo jwt para drf (se llama simple-jwt), y configuré las URL como se indica en los documentos, ¿cómo soluciono el error? En el backend, se supone que todo el proceso de inicio de sesión ser solicitud POST: urls.py

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

ahora para la parte de reacción (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 answers
Answer question

0

La solicitud incorrecta de Django 400 se debe a muchas razones que incluyen sintaxis incorrecta, extensiones corruptas, URL incorrecta, etc. Puedes intentar estos pasos:

  1. Puede ser que la variable ALLOWED_HOSTS no esté configurada correctamente: asegúrese de que ALLOWED_HOSTS = ['127.0.0.1', 'localhost'] , ya que se trabaja en local.

  2. Borrando el caché para corregir el error de solicitud incorrecta 400. El caché también puede crear problemas, borre el caché e intente verificar si el error desaparece.

  3. También puede ser causado por extensiones corruptas, entonces tenga en cuenta las extensiones instaladas con las que trabaja.

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!