This page explains how to remotely develop your Django project on a CentOS server using Visual Studio Code (VS Code) from a Windows environment, and how to directly run Django's built-in development server, runserver
, without the full web server stack for development purposes.
9. VS Code Remote Development (Windows)
This section guides you on how to develop remotely by connecting directly to your server using VS Code's Remote - SSH extension.
- Install the
Remote - SSH
extension in VS Code. - Add server information to your
.ssh/config
file:Host your_server_alias HostName your_server_ip_address User your_username IdentityFile ~/.ssh/your_private_key_file_path
- Connect to the server by clicking the green icon in the bottom-left of VS Code and selecting 'Remote-SSH: Connect to Host...'.
- In the connected VS Code window, open the
/home/hello
directory via 'File > Open Folder'. - In the VS Code terminal, run
source venv/bin/activate
and proceed with development.
10. (Additional) Development Run: runserver
For development and testing purposes, you can directly run Django's built-in development server without the Apache/Gunicorn web servers. It typically uses port 8000.
cd /home/hello # Change to project directory
source venv/bin/activate # Activate virtual environment
python manage.py runserver 0.0.0.0:8000 # Run development server (allow all IPs on port 8000)
Allowing External Access (Caution: Use only in development environments):
sudo firewall-cmd --permanent --add-port=8000/tcp # Permanently allow TCP port 8000 in Firewalld
sudo firewall-cmd --reload # Reload firewall settings
sudo semanage port -a -t http_port_t -p tcp 8000 # Allow port 8000 in SELinux
Access address: http://<Your Server IP>:8000/