Helloworld Project and Sample App

Learn to set up a "HelloWorld" project for Django Administration by creating your first app named "sample_app".

Project setup and creation

To run a Django application on Educative, you do not need to set up anything. All the code will run inside the special environment within the browser. It’s as easy as that!

Educative is designed in such a way that you do not get distracted by dependencies and, instead, get right into what is essential: learning.

Together, we will go through all the steps of installation so that you have an idea of what is happening in the background.

First, you need to install the virtual environment and activate it immediately.

virtualenv -p python3 django_env

source django_env/bin/activate

Now you will install Django:

pip install django

and create your Django project helloworld. You will use this project throughout the course.

django-admin startproject helloworld

Now you will create our application sample_app inside the helloworld project.

cd helloworld
python manage.py startapp sample_app

For this course, the default SQLite database will be used. Since the focus will be on the Django Admin part, we can launch the migration to create the tables required by our Django project.

python manage.py migrate

Now you can create your superuser which will be used to access the Django Admin interface.

python manage.py createsuperuser

After running the above command, you will be asked to provide the username and password of your choice. Once those are established, your Django Project will be set up successfully and now you will be able to access the Django admin interface.

To start the Django server and access the Django Admin interface, you will need to run the following command:

python manage.py runserver

The output of the terminal will look something like this when the server has been successfully started.

Terminal output after running the server.
Terminal output after running the server.

Running the Django server on the Educative platform

When you press the Run button in the following code widget, a Django web server is started with the above command, and everything is already set up for you. Subsequently, once the server is started, you will see the welcome screen in the “Output” tab. You can open the Django admin page by visiting the URL given below. To do so, paste it in a new browser tab, and hit enter.

Press + to interact
{{EDUCATIVE_LIVE_VM_URL}}/admin

Once the Django Admin page is open, you will need credentials to log in. You can use the following credentials to log in to your admin account:

  • Username: educative
  • Password: edu1234
#!/usr/bin/env python
"""Django's command-line utility for administrative tasks."""
import os
import sys


def main():
    """Run administrative tasks."""
    os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'helloworld.settings')
    try:
        from django.core.management import execute_from_command_line
    except ImportError as exc:
        raise ImportError(
            "Couldn't import Django. Are you sure it's installed and "
            "available on your PYTHONPATH environment variable? Did you "
            "forget to activate a virtual environment?"
        ) from exc
    execute_from_command_line(sys.argv)


if __name__ == '__main__':
    main()
Execute all the changes in this code widget.

Hurray! You have successfully created your first project and application, and also configured your admin account.