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

执行python manage.py runserver无响应,Django开发服务器无法访问求助

Troubleshooting Django Runserver & Migrate Issues (No Output, Unreachable Server)

Hey there, let's work through this tricky problem you're having—totally get how frustrating it is when you're just starting with Django and hit a roadblock like this! Let's break down some fixes step by step:

1. Fix the "No Output" Runserver Issue First

The fact that you only see startup logs after hitting Ctrl+C suggests output might be buffered, or the server is hanging before it can write to the console. Try this quick fix first:

  • Run the server with unbuffered output:
    python -u manage.py runserver
    
    The -u flag forces Python to skip output buffering, so you should see the startup logs right away instead of waiting for a buffer flush.

2. Check for Port Conflicts

If the server claims it's starting on http://127.0.0.1:8000/ but you can't access it, another program might be hogging port 8000:

  • Windows: Open Command Prompt and run:
    netstat -ano | findstr :8000
    
    Look for a process ID (PID) in the last column, then end that process via Task Manager. Or just run Django on a different port:
    python manage.py runserver 8001
    
  • Mac/Linux: Open Terminal and run:
    lsof -i :8000
    
    Kill the conflicting process with kill <PID>, or switch ports like the example above.

3. Verify Django Settings Configuration

Double-check these critical settings in your settings.py file:

  • ALLOWED_HOSTS: Make sure it includes your local address. For development, set it to:
    ALLOWED_HOSTS = ['127.0.0.1', 'localhost']
    
    An empty ALLOWED_HOSTS can cause access issues in some Django versions or environments.
  • DATABASES: If using default SQLite, confirm the NAME path is correct and your user has read/write permissions for that file. If using MySQL/PostgreSQL, check that connection details (host, user, password) are accurate and the database server is running.

4. Fix Unresponsive Migrate Commands

If python manage.py migrate does nothing, try these steps:

  • First run python manage.py makemigrations to generate migration files (if you've added models to your apps). If this command also has no output, Django isn't detecting model changes or there's a configuration error.
  • Run python manage.py check to scan your project for configuration issues—this will flag problems like missing installed apps, invalid settings, or broken model definitions.
  • Ensure all your apps are listed in INSTALLED_APPS in settings.py—Django won't process migrations for unregistered apps.

5. Check Your Virtual Environment (If Using One)

If you're using a virtual environment, make sure it's activated before running commands. Accidentally using the system-wide Python instead of your venv can lead to missing dependencies or version mismatches:

  • Windows:
    venv\Scripts\activate
    
  • Mac/Linux:
    source venv/bin/activate
    
    If activation fixes the issue, reinstall Django in your venv to ensure all dependencies are properly set up:
    pip install django==2.1.5
    

Give these steps a try one by one—most likely one of these will get your Django project up and running!

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.08 18:12:31