Django请求favicon.ico或Admin CSS文件时触发ConnectionResetError[Errno54]
Hey there, I’ve dealt with these annoying console errors before—even though your frontend works perfectly fine, those tracebacks are definitely distracting. Let’s walk through some practical fixes to get rid of that ConnectionResetError: [Errno 54] Connection reset by peer issue:
1. Disable Auto-Reload in the Development Server
The Django dev server’s auto-reload feature can sometimes clash with static file requests, causing premature connection closures. Try starting your server with the --noreload flag:
python manage.py runserver --noreload
This turns off automatic code reloading, which often eliminates the connection reset errors triggered by admin CSS or favicon requests.
2. Verify Static File Configuration
Even though you’re getting 200 responses for admin assets, double-check your setup to rule out subtle path or caching glitches:
- Ensure
django.contrib.staticfilesis listed in yourINSTALLED_APPSinsettings.py. - Confirm
DEBUG = True(default for development) so Django serves static files directly. - Run
collectstaticto gather all admin static assets (unnecessary for dev, but can fix odd caching issues):python manage.py collectstatic
3. Rule Out Browser/Plugin Interference
Sometimes the issue comes from the client side:
- Clear your browser’s cache and cookies, then reload the page.
- Test in incognito/private mode to bypass cached assets and disable extensions.
- Temporarily turn off ad blockers, VPNs, or proxy tools—these can interrupt static file connections mid-transfer.
4. Update Python/Django to Latest Patch Versions
While Django 3.0.4 supports Python 3.6, specific minor versions might have known connection-handling bugs:
- Upgrade Python 3.6 to the latest patch release (e.g., 3.6.15) to fix socket-related issues in the standard library.
- Update Django to the latest version in the 3.0.x branch (e.g., 3.0.14) to patch server-side connection bugs.
Quick Context on the Error
This error usually means your browser closed the connection before Django finished sending the full response. Since the frontend already received enough of the static file to render correctly, you don’t see functionality issues—but the server logs the abrupt closure as an error. The fixes above target the most common triggers for these premature closures in a development environment.
内容的提问来源于stack exchange,提问作者m0dknight

