Django Simple Web App
Learn how to set up and run a Django project on the Educative platform.
We'll cover the following
Running a simple web app
After setting up the docker, it’s time to run a simple Django web app.
from django.db import models # Create your models here.
It’s evident from the file tree in the widget above that we only show the necessary files to the users. Therefore, in case of Django, we don’t need to show the __pycache__
and migrations
folders and the db.sqlite3
file.
The idea is to keep the project in a separate directory and show only the necessary files to the user in the Single Page App (SPA) widget. The user can view and update the files in the SPA widget. When they press the “Run” button, the files from the widget are copied to the project folder and run from there.
Allowed hosts
One of the configurations in the settings.py
file is the ALLOWED_HOSTS
field. We can put '*'
there but that’s less secure. We need to put the exact host URL where the app is running. On Educative, this URL is different for every user and can’t be specified as it is. In this case, we can use the {{EDUCATIVE_LIVE_VM_URL}}
API key in the code as shown below:
ALLOWED_HOSTS = ['{{EDUCATIVE_LIVE_VM_URL}}'.replace('https://','')]
The {{EDUCATIVE_LIVE_VM_URL}}
key is replaced by the custom live VM URL of the user as shown in line 28 in the code above.