To setup and install Django server on any of the cloud platforms, the recommended way is to setup a VM using the Django image available from the marketplace. Details below:
Setting up Django
Once logged in, to check the current version of Django, you can run the following command:
django-admin startproject mysite
Once the Django project has been created, change the directory to mysite and migrate the changes with the following commands:
python3 manage.py migrate
You should get the following output:
Create Django Admin User Account
Next, you will need to create an admin user account for managing the Django project. This will allow you to login to the Django web portal. You can create it with the following command:
python3 manage.py createsuperuser
Start Django Application
By default, the Django application can not be accessed from the remote hosts. So you will need to allow Django for external hosts. You can do it by adding your server IP in settings.py. Run the following command, change the mysite folder directory depending on where you’ve installed Django
sudo nano mysite/settings.py
Change the following line:
ALLOWED_HOSTS = [‘your-server-ip’] – Make sure to add the quotations ‘ ‘
Save and close the file. Then, start the Django application with the following command:
Make sure you’re still in your Django root application folder.
python3 manage.py runserver 0.0.0.0:8000
You should see the following output:
Django application has now started and runs on port 8000.
Go to your ServerIP:8000 and you should see the following page:
To use the administrative web admin, Access with /admin
Login with username and password which was setup earlier.
Thats it, you’re now ready to start building your first app.
Django Firewall Ports
By default Django uses the following firewall ports:
If you are using any of the cloud security groups and need to change / add ports refer to the following guides:
To setup AWS firewall rules refer to – AWS Security Groups
To setup Azure firewall rules refer to – Azure Network Security Groups
To setup Google GCP firewall rules refer to – Creating GCP Firewalls
Disclaimer: Django is a registered trademark owned by Django Software Foundation (DSF) and is licensed under BSD license. No warrantee of any kind, express or implied, is included with this software. Use at your risk, responsibility for damages (if any) to anyone resulting from the use of this software rest entirely with the user. The author is not responsible for any damage that its use could cause.