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

Django 2.2.8在虚拟主机与VPS上配置失败,访问显示空白页

Troubleshooting Blank Page Issues When Deploying Django 2.2.8 on VPS/Virtual Hosting

Hey there, let’s work through figuring out why you’re seeing a blank page after setting up Django 2.2.8 on your server. I’ve tackled similar deployment headaches before, so let’s break this down step by step:

1. Enable Debug Mode & Check Error Logs

First, temporarily set DEBUG = True in your project’s settings.py—this will replace the blank page with detailed error messages (just remember to switch it back off for production!). If you still don’t see errors, dig into your server’s logs:

  • For Apache: Check /var/log/apache2/error.log
  • For Nginx: Look at /var/log/nginx/error.log
  • On shared hosting, your provider probably has a dedicated log section in their control panel

Also, double-check your ALLOWED_HOSTS setting includes your domain or server IP, like:

ALLOWED_HOSTS = ['your-domain.com', '123.45.67.89']

2. Validate Your WSGI Configuration

Since you followed a shared hosting guide, the WSGI setup is likely where things went wrong. Verify these key points:

  • Make sure your wsgi.py file points to your virtual environment’s Python interpreter. Add this at the top if it’s missing:
activate_this = '/path/to/your/python_files/venv/bin/activate_this.py'
with open(activate_this) as file_:
    exec(file_.read(), dict(__file__=activate_this))
  • Confirm the WSGI file correctly loads your project settings. The line should look like:
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'your_site.settings')
  • For Apache, check your .htaccess file to ensure it routes requests to the WSGI script properly. A typical entry might be:
RewriteEngine On
RewriteRule ^(.*)$ /path/to/wsgi.py/$1 [L]

3. Fix File Permissions

Django needs read access to your project files and write access to folders like static or media:

  • Set the web server user (usually www-data for Apache, nginx for Nginx) as the owner of your project:
sudo chown -R www-data:www-data /path/to/your_site
  • Apply proper directory and file permissions:
find /path/to/your_site -type d -exec chmod 755 {} \;
find /path/to/your_site -type f -exec chmod 644 {} \;
  • If you have a static directory, run python manage.py collectstatic (ensure STATIC_ROOT is correctly defined in settings.py first).

4. Test Django Locally on the Server

Connect via SSH and run the Django dev server to check if the project works directly:

cd /path/to/your_site
source /path/to/python_files/venv/bin/activate
python manage.py runserver 0.0.0.0:8000

Then access http://your-server-ip:8000 from your local machine (make sure port 8000 is open in your firewall). If this works, the issue is with your web server config—not Django itself.

5. Recheck Installed Dependencies

Even if you ran pip install -r requirements.txt, some packages might have failed to install. Reactivate your virtual environment and verify:

source /path/to/python_files/venv/bin/activate
pip list

Confirm Django==2.2.8 and all other required packages (like psycopg2 for PostgreSQL) are listed. Reinstall any missing ones with pip install package-name.


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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.14 09:08:49