DEV Community

Vicente G. Reyes
Vicente G. Reyes

Posted on • Updated on

Django Startup Sequence

Originally posted on https://highceburg.tech.blog

Initializing project directory, installing the virtual environment and django:

mkdir _project_name_
cd project_name
virtualenv _dir_name_
. ./_dir_name_/bin/activate
python -m pip install django

To test if the installation worked, inside the virtual environment command prompt, start the interactive interpreter by typing

python

If the installation is successful, you should be able to import the django module and check the what version was installed:

Python 3.10.0 (default, Oct 14 2021, 20:54:55) [Clang 13.0.0 (clang-1300.0.29.3)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import django
>>> django.get_version()
'3.2.8'
>>> 

Exit interpreter once done.

Starting a project:

django-admin startproject _app_name_ 

Creating a Database:

Inside the created folder in the last step, run the following command:

python -m manage migrate

This creates a sqlite database and any necessary database tables. If all goes well, this is what you'll see:

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 sessions.0001_initial... OK

The Development Server:

To verify the migration, run:

python -m manage runserver

You will see the following output on the command line:

Watching for file changes with StatReloader
Performing system checks...

System check identified no issues (0 silenced).
April 22, 2019 - 15:24:21
Django version 2.2, using settings 'app.settings'
Starting development server at http://127.0.0.1:8000/
Quit the server with CONTROL-C.

That's all folks!

Reference:
Build your first website with Python and Django: Build and Deploy a website with Python & Django

Top comments (0)