Python 3x Pandas Django

Django Admin Interface

This tutorial begins where our previous tutorial session basic request and response left off. In this tutorial session, we’ll setup the database, create your first model, and get a quick introduction to Django’s automatically-generated admin site.

Database Setup

Now, open up myfirstsite/ It’s a normal Python module with module-level variables representing Django settings.

By default, the configuration uses SQLite. If you’re new to databases, or you’re just interested in trying Django, this is the easiest choice. SQLite is included in Python, so you won’t need to install anything else to support your database. When starting your first real project, you may want to use a more scalable database like PostgreSQL,Mysql , Oracle to avoid database-switching headaches down the road.

Copied below lines from myfirstsite/, Django default configurations uses SQLite 'django.db.backends.sqlite3'

    'default': {
        'ENGINE': 'django.db.backends.sqlite3',
        'NAME': BASE_DIR / 'db.sqlite3',

If you wish to use another database, install the appropriate database bindings and change the following keys in the databases 'default' item to match your database connection settings:

• ENGINE – 'django.db.backends.sqlite3', 'django.db.backends.postgresql', 'django.db.backends.mysql', or '' or some other engines are available.

• NAME – The name of your database. If you’re using SQLite, the database will be a file on your computer; in that case, NAME should be the full absolute path, including filename, of that file. The default value, BASE_DIR / 'db.sqlite3', will store the file in your project directory.

If you are not using SQLite as your database, additional settings such as USER, PASSWORD, and HOST must be added.

For Example, PostgreSQL: (We will see each DBs connection parameters in our upcoming tutorial sessions)

When you connecting to PostgreSQL database additional connection parameters will be required something similar to the below one,

    'default': {
        'ENGINE': 'django.db.backends.postgresql',
        'NAME': 'mydatabase',
        'USER': 'mydatabaseuser',
        'PASSWORD': 'mypassword',
        'HOST': '',
        'PORT': '5432',

Also, note the INSTALLED_APPS setting at the top of the file. That holds the names of all Django applications that are activated in this Django instance. Apps can be used in multiple projects, and you can package and distribute them for use by others in their projects.

By default, INSTALLED_APPS contains the following apps, all of which come with Django:


Copied above lines from myfirstsite/, Django comes with some default apps.

These applications are included by default as a convenience for the common case.

Some of these applications make use of at least one database table, though, so we need to create the tables in the database before we can use them. To do that, run the following command:

python migrate

The migrate command looks at the INSTALLED_APPS setting and creates any necessary database tables according to the database settings in your myfirstsite/ file and the database migrations shipped with the app (we’ll cover those later). You’ll see a message for each migration it applies. Let’s check our command prompt after running comment python migrate

You’ll see the following output on the command line:

(tutorial1-env) C:\Users\user\tutorial1>python migrate
Operations to perform:
  Apply all migrations: admin, auth, contenttypes, sessions
Running migrations:
  Applying contenttypes.0001_initial... OK
  Applying auth.0001_initial... OK
  Applying admin.0001_initial... OK
  Applying admin.0002_logentry_remove_auto_add... OK
  Applying admin.0003_logentry_add_action_flag_choices... OK
  Applying contenttypes.0002_remove_content_type_name... OK
  Applying auth.0002_alter_permission_name_max_length... OK
  Applying auth.0003_alter_user_email_max_length... OK
  Applying auth.0004_alter_user_username_opts... OK
  Applying auth.0005_alter_user_last_login_null... OK
  Applying auth.0006_require_contenttypes_0002... OK
  Applying auth.0007_alter_validators_add_error_messages... OK
  Applying auth.0008_alter_user_username_max_length... OK
  Applying auth.0009_alter_user_last_name_max_length... OK
  Applying auth.0010_alter_group_name_max_length... OK
  Applying auth.0011_update_proxy_permissions... OK
  Applying auth.0012_alter_user_first_name_max_length... OK
  Applying sessions.0001_initial... OK

Re-start your development server by running command python runserver and you will see the following output on the command line.

(tutorial1-env) C:\Users\user\tutorial1>python runserver
Watching for file changes with StatReloader
Performing system checks...

System check identified no issues (0 silenced).
August 30, 2021 - 17:43:10
Django version 3.2.6, using settings 'myfirstsite.settings'
Starting development server at
Quit the server with CTRL-BREAK.

Notice below errors are gone now because we ran python migrate as it required for DB’s migrations:

You have 18 unapplied migration(s). Your project may not work properly until you apply the migrations for app(s): admin, auth, contenttypes, sessions.
Run 'python migrate' to apply them.

Now that the server’s running, visit with your Web browser. You’ll see a “Hello, World.” Page. It worked!

Introducing the Django Admin

One of the most powerful parts of Django is the automatic admin interface. It reads metadata from your models to provide a quick, model-centric interface where trusted users can manage content on your site.

The admin interface isn’t intended to be used by site visitors. It’s for site managers\admin who manage your site.

Creating an admin user,

We’ll need to create a user who can login to the admin site by running the following command: python createsuperuser

Go to your command prompt quit the server with CTRL-BREAK and run the following command:

python createsuperuser


Enter your desired username and press enter. (I have added admin as Username)


You will then be prompted for your desired email address: (It’s n0t a mandatory field so I left as Blank)


The final step is to enter your password. You will be asked to enter your password twice, the second time as a confirmation of the first.


Start the development server by running the following command:

python runserver

Now, open a Web browser and go to “/admin/” on your local domain – You should see the admin’s login screen:


And try logging in with the superuser account you created in the previous step. You should see the Django admin index page:


You should see a few types of editable content: groups and users. They are provided by django.contrib.auth, the authentication framework shipped by Django.

Congratulations! You have successfully completed Django admin site tutorial session. Let us move to the next topic Django Models.

If you have any doubts or queries related to this chapter, get them clarified from our Python Team experts on ibmmainframer Community!