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

Django/Vue项目结合django-livereload-server运行异常求助

Troubleshooting Inconsistent Django/Vue Runtime Issues with Livereload

Hey there, let's work through those flaky runtime issues in your Django/Vue setup. Based on what you described, here's a breakdown of likely culprits and actionable fixes:

Possible Root Causes

  • Session & Cache Conflicts: Even though you figured out running livereload and runserver in separate sessions, leftover cache from your earlier setup changes (like clearing browser history) might still be causing mismatches.
  • Stale Asset Caching: Clearing browser history doesn't always wipe all cached Vue assets, and Django's static file serving or Vue's dev server could be holding onto old files.
  • Implicit Livereload Config Gaps: The docs might have skipped some unspoken steps to ensure livereload plays nice with both Django's backend and Vue's frontend.

Step-by-Step Fixes

  1. Full Reset of Dev Environment

    • Shut down both livereload and runserver processes completely (don't just background them).
    • Clear Django's local cache with this command in your project root:
      python manage.py clearcache
      
    • For Vue, delete the cache folder specific to your build tool:
      • Vite: Wipe node_modules/.cache
      • Vue CLI: Delete node_modules/.hot
    • Clear your browser's full cache (not just history) – include cached files, images, and cookies tied to your local dev domain.
  2. Lock in the Dual Session Setup

    • Open your first terminal, navigate to your Django root, and start livereload:
      python manage.py livereload
      
      Confirm you see logs showing the server is running (usually on port 35729).
    • Open a separate, fresh terminal session, stay in the Django root, and launch the dev server:
      python manage.py runserver
      
      Check that Django's startup logs mention livereload integration – this confirms the two processes are talking to each other.
  3. Sync Vue & Django Static Assets

    • If you're running Vue's dev server alongside Django, double-check your Vue config is proxying API requests to Django's runserver (typically port 8000).
    • If you build Vue assets into Django's static folder, run your Vue build command (e.g., npm run build) after clearing cache, then restart both servers to ensure fresh assets are served.
  4. Validate Livereload Settings

    • Open your Django settings.py and confirm:
      • 'livereload.middleware.LiveReloadScript' is added to the end of your MIDDLEWARE list.
      • DEBUG is set to True (livereload only works in development mode).
      • Your local dev domain (like localhost:8000) is included in ALLOWED_HOSTS.

Quick Sanity Check

After setting everything up:

  • Open your browser's developer tools (F12), go to the Network tab, and verify all Vue assets load with a 200 status (no 404s or stale cached files).
  • Check your page source for the livereload script – you should see a tag like <script src="http://localhost:35729/livereload.js"></script>.

If issues persist, test in an incognito/private window to rule out any remaining browser session or cache quirks.

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.21 07:16:19