Tuesday, April 22, 2025

Django To-Do - Creating Django App


C:\>pip install django
Collecting django
  Using cached Django-3.0.8-py3-none-any.whl (7.5 MB)
Requirement already satisfied: pytz in c:\python38-64\lib\site-packages (from django) (2020.1)
Requirement already satisfied: asgiref~=3.2 in c:\python38-64\lib\site-packages (from django) (3.2.10)
Requirement already satisfied: sqlparse>=0.2.2 in c:\python38-64\lib\site-packages (from django) (0.3.1)
Installing collected packages: django
Successfully installed django-3.0.8

C:\>

The command "pip install django" is used to install Django. It is a package that can be installed using pip, a package installer for Python.

Pip is the standard package manager for Python, and it simplifies the process of installing and managing Python packages. By running the "pip install" command followed by the package name, you can download and install the package and all its dependencies automatically.

In the case of Django, running "pip install django" will download and install the latest version of Django available from the official Python Package Index (PyPI) repository, along with any other packages required for it to run. This command is essential if you want to start developing web applications using Django in Python. 


C:\>django-admin startproject todo_generic

C:\>

This command creates a new Django project named "todo_generic" in the current directory (C:). The "django-admin" is a command-line utility that ships with Django and provides various tools and utilities for creating and managing Django projects.

The "startproject" option is used to create a new Django project, and "todo_generic" is the name of the project. This command creates a directory named "todo_generic" in the current directory and populates it with the basic files and directories required to start a Django project. 


C:\todo_generic>dir
 Volume in drive C is New Volume
 
 Directory of C:\todo_generic

07/27/2020  02:14 PM    <DIR>          .
07/27/2020  02:14 PM    <DIR>          ..
07/27/2020  02:14 PM               653 manage.py
07/27/2020  02:14 PM    <DIR>          todo_generic
               1 File(s)            653 bytes
               3 Dir(s)  77,539,221,504 bytes free

C:\todo_generic>

C:\todo_generic>cd todo_generic

C:\todo_generic\todo_generic>dir
 Volume in drive C is New Volume
 Volume Serial Number is B082-0A47

 Directory of C:\todo_generic\todo_generic

07/27/2020  02:14 PM    <DIR>          .
07/27/2020  02:14 PM    <DIR>          ..
07/27/2020  02:14 PM               417 asgi.py
07/27/2020  02:14 PM             3,226 settings.py
07/27/2020  02:14 PM               775 urls.py
07/27/2020  02:14 PM               417 wsgi.py
07/27/2020  02:14 PM                 0 __init__.py
               5 File(s)          4,835 bytes
               2 Dir(s)  77,534,949,376 bytes free

C:\todo_generic\todo_generic>

C:\todo_generic>python manage.py runserver
Watching for file changes with StatReloader
Performing system checks...

System check identified no issues (0 silenced).

You have 17 unapplied migration(s). Your project may not work properly until you apply the migrations for app(s): admin, auth, contenttypes, sessions.
Run 'python manage.py migrate' to apply them.
July 27, 2020 - 14:19:22
Django version 3.0.8, using settings 'todo_generic.settings'
Starting development server at http://127.0.0.1:8000/
Quit the server with CTRL-BREAK.

This command starts the development server of the Django project. When you run this command, Django starts the server and makes your application available at a specific URL (by default, http://localhost:8000/). You can then use a web browser to visit that URL and interact with your application. The server listens for incoming requests, processes them, and sends back responses. You can use Ctrl + C in the command prompt to stop the server.

Cancel our server for now, because we need to create dedicated todo app inside main todo_generic project.


C:\todo_generic>python manage.py startapp todo

C:\todo_generic>

This command creates a new Django app named todo in the current directory (C:\todo_generic). The app's directory structure will be created automatically with a set of default files including an admin.py, models.py, tests.py, and views.py file. This command is used to create a new app in a Django project. 


C:\todo_generic>cd todo

C:\todo_generic\todo>dir
 Volume in drive C is New Volume
 Volume Serial Number is B082-0A47

 Directory of C:\todo_generic\todo

07/27/2020  02:24 PM    <DIR>          .
07/27/2020  02:24 PM    <DIR>          ..
07/27/2020  02:24 PM                66 admin.py
07/27/2020  02:24 PM                88 apps.py
07/27/2020  02:24 PM    <DIR>          migrations
07/27/2020  02:24 PM                60 models.py
07/27/2020  02:24 PM                63 tests.py
07/27/2020  02:24 PM                66 views.py
07/27/2020  02:24 PM                 0 __init__.py
               6 File(s)            343 bytes
               3 Dir(s)  77,550,043,136 bytes free

C:\todo_generic\todo>

C:\todo_generic\todo>cd..

C:\todo_generic>python manage.py 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 sessions.0001_initial... OK

C:\todo_generic>

The python manage.py migrate command in Django is used to apply all the migrations to the database. It syncs the database schema with the current set of models and also updates the existing tables with any changes made to the models.

This command is used after creating new models or making changes to the existing models in Django.

In this specific case, the command is being run in the todo_generic project directory to apply any migrations that may be required based on the models defined in the project. 


C:\todo_generic>python manage.py createsuperuser
Username (leave blank to use 'user'): admin
Email address: admin@server.com
Password:
Password (again):
The password is too similar to the username.
This password is too short. It must contain at least 8 characters.
This password is too common.
Bypass password validation and create user anyway? [y/N]: y
Superuser created successfully.

C:\todo_generic>

This command is used to create a superuser account for the Django application. A superuser has all the permissions and access to the Django application, including the ability to add, modify or delete any data.

When this command is executed, Django will prompt the user to enter a username, email address, and password for the superuser. Once the user provides this information, the superuser account will be created and can be used to log in to the Django application's admin panel. 


C:\todo_generic>python manage.py runserver
Watching for file changes with StatReloader
Performing system checks...

System check identified no issues (0 silenced).
July 27, 2020 - 14:28:56
Django version 3.0.8, using settings 'todo_generic.settings'
Starting development server at http://127.0.0.1:8000/
Quit the server with CTRL-BREAK.

Now we can access homepage at http://127.0.0.1:8000, but also admin panel (Django Administration) is available at http://127.0.0.1:8000/admin

Go login with admin/pass combination you choose. In next tutorial we will understand routing in Django.

No comments:

Post a Comment

Tkinter Introduction - Top Widget, Method, Button

First, let's make shure that our tkinter module is working ok with simple  for loop that will spawn 5 instances of blank Tk window .  ...