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

Django项目执行runserver命令报错,8000/8009端口均无法启动

Common Reasons for Django runserver Failure (Even When Switching Ports)

Hey there! Since you didn’t share the exact error output you’re getting when running python manage.py runserver 8009 or 8000, I’ll break down the most frequent culprits that cause this issue:

  • Hidden port occupation: Sometimes, even after switching ports, the previous runserver process might not have terminated properly (e.g., you closed the terminal without stopping it first). To check this:

    • On Windows: Run netstat -ano | findstr :8009 to find the PID of the process using the port, then kill it with taskkill /F /PID <your-pid>.
    • On macOS/Linux: Use lsof -i :8009 to locate the process, then terminate it with kill -9 <your-pid>.
  • Misconfigured project settings:

    • If your settings.py has an empty ALLOWED_HOSTS list (or doesn’t include 'localhost'/'127.0.0.1'), Django will throw a security error when starting the server. Add at least one of these values to fix it.
    • Database configuration errors (e.g., incorrect credentials, the database server isn’t running) will prevent the server from initializing. Double-check the DATABASES section in settings.py and ensure your database service is active.
  • Virtual environment or dependency issues:

    • You might be running the command outside your activated virtual environment, meaning Django isn’t installed in your global Python context. Check if your terminal prompt shows the virtual environment name (e.g., (myenv)), and activate it if needed.
    • Incompatible Django versions: If your project was built with an older Django version but you installed a newer one, there could be breaking changes. Verify the required version in your requirements.txt and reinstall with pip install -r requirements.txt.
  • Missing or corrupted project files:

    • If manage.py is modified or corrupted, it can fail to launch the server. Try restoring a clean version of this file if possible.
    • Unapplied database migrations: If you’ve added new models but haven’t run python manage.py migrate, the server might throw errors related to missing database tables. Run the migration command first before starting the server.
  • Permission problems:

    • While ports 8000/8009 don’t require root access, you might lack read/write permissions for project files (e.g., log files, database files). Ensure your user has the necessary permissions for the project directory.

If you can share the exact error message from your terminal, I can give you a more targeted solution!

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.19 03:34:59