You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Django登录时静态资源404且未跳转至个人页问题排查求助

Let's break down your problem and walk through targeted troubleshooting steps, plus clarify how Django's login redirect should work normally.

Troubleshooting Directions

  • Check your login view's post-success logic
    The log shows your POST /accounts/login/ returns a 200 status code—this is unusual for a successful login, which should return a 302 redirect. This means your view is probably rendering a template directly instead of redirecting to the user's profile page. Double-check:
    • Did you accidentally replace a return redirect(...) with a return render(...) in the login view?
    • If using Django's built-in LoginView, did you override the get_success_url() method incorrectly, or modify the LOGIN_REDIRECT_URL setting to point to a broken page?
  • Verify the broken page's static resource paths
    The 404s for main.css and images happen because the page being loaded is looking for /static/core/bundles/main.css, but your actual file is at /static/core/bundles/css/main.css. Since other pages load this CSS correctly, the issue is specific to the template being rendered after login:
    • Check the "load failed" template for incorrect {% static %} tags. For example, it might have {% static 'core/bundles/main.css' %} instead of {% static 'core/bundles/css/main.css' %}.
    • Those unexpected images confirm the wrong template is being loaded entirely—this page shouldn't appear after login at all.
  • Confirm user authentication status
    Even though the POST returns 200, make sure the user is actually being authenticated. Add debug prints in your login view (like print(request.user.is_authenticated) after calling authenticate()) or check the session in your browser dev tools. If authentication is failing silently, the view might be falling back to rendering the wrong error page instead of the login form with an error message.
  • Check for middleware interference
    If you have custom middleware that runs after login, it might be intercepting the redirect and forcing a different page to load. Disable any recently added middleware temporarily to see if the redirect starts working again.

Normal Django Login Redirect Logic

Whether you're using Django's built-in auth views or a custom one, the successful login flow should follow this pattern:

  1. User submits login credentials via POST to /accounts/login/.
  2. The view uses authenticate() to verify the credentials.
  3. If valid, login(request, user) is called to set the user's session.
  4. The view returns a 302 redirect (not a 200) to the configured success URL:
    • For built-in LoginView, this uses the LOGIN_REDIRECT_URL setting (default is /accounts/profile/), or the next parameter if provided in the login form.
    • For a custom view, you'd explicitly return return redirect('profile-url-name') or the direct URL of the user's profile page.
  5. If authentication fails, the view renders the login template again (200 status) with an error message, not an unrelated "load failed" page.

The core issue here is that your login flow isn't hitting that redirect step—instead, it's rendering an incorrect template with broken static paths and unwanted images. Start by fixing the view's post-authentication return value, then clean up any template path issues if needed.

内容的提问来源于stack exchange,提问作者emma_lynn_rose

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.15 06:37:07