CREATING DJANGO WEB APPLICATION-GETTING STARTED
Django Web Framework provides support to developers in developing web applications. Django is based on the model - view - template architecture and within the root folder, certain, necessary files and folders should be created according to a specific rule.
To remind, the description of the application would be as follows:
The application should allow the user to create a logo by offering the initial version for the logo based on the name or company name entered, allow the user to edit the logo, save it, and then download it to their computer. The application should also have a section for registration, as well as user login. Below you will find only a part of the applications that consist of home page, part for user registration, as well as for user login. It will also show how to create a database, superuser and how to use Django's admin interface to manage registered users. When the user enters in the field for one name or title, a redirect to the registration page will be performed. After successful registration, and then login to the system, the user will load the next page on which the category for the logo will be selected and where the initial version of the logo will be offered. |
Start creating a video application |
GIT installation
The appropriate git installer can be downloaded from https://git-scm.com/download/win
It is a program that enables communication between a remote server and a local folder (repository). It is actually a version control system.
Another way is to install the github desktop application, which then also installs git:
https://desktop.github.com/
The
It is a program that enables communication between a remote server and a local folder (repository). It is actually a version control system.
Another way is to install the github desktop application, which then also installs git:
https://desktop.github.com/
The
Heroku CLI(heroku command line interface)
A system of commands for working on the premises and various commands for the development of the application on the premises and on the heroku site. Download and run the appropriate installer from the website:
https://devcenter.heroku.com/articles/getting-started-with-python#set-up
https://devcenter.heroku.com/articles/getting-started-with-python#set-up
Command for loging user on website: heroku login
Creating applications locally using DJANGO framework
Usefull tutorijal: https://www.tutorialspoint.com/django/index.htm
One way to install dangoo is by using the command prompt and the pip package to install dangoo. Type:
pip install Django==3.0
pip install Django==3.0
If you haven't already, you need to install the "postgresql" database. An adapter for the "psycopg2" python is required.
All packages required by the project should be listed in the "requirements.txt" file. This will be done with a command in the "command prompt". It will be described later.
Installing a virtual environment for Python: https://virtualenv.pypa.io/en/latest/
All packages required by the project should be listed in the "requirements.txt" file. This will be done with a command in the "command prompt". It will be described later.
Installing a virtual environment for Python: https://virtualenv.pypa.io/en/latest/
Django framework installation
Type the following command in the command prompt:
python -m pip install Django
Creating a Django project
To create an application skeleton on a local computer in Command Prompt, you need to bring it to the superfolder in which the root application will be created and then type the following command:
django-admin startproject myproject
For example. to create a project called logo_creator located on the localhost in the directory:
C:\websites\repozitory
First you need to change the path to that directory in Command-Prompt, and then type the command:
C:\websites\repozitory
First you need to change the path to that directory in Command-Prompt, and then type the command:
django-admin startproject logo_creator
A folder logo_creator is created whose structure is:
myproject/
manage.py
myproject/
__init__.py
settings.py
urls.py
wsgi.py
In the observed example:
logo_creator /
manage.py
logo_creator /
__init__.py
settings.py
urls.py
wsgi.py
myproject/
manage.py
myproject/
__init__.py
settings.py
urls.py
wsgi.py
In the observed example:
logo_creator /
manage.py
logo_creator /
__init__.py
settings.py
urls.py
wsgi.py
The manage.py file is served with the project via the line command.
Other files must be placed in a subfolder that has the same name as the project itself and contains the following files:
__init__.py
settings.py- Project-related settings are entered here
urls.py-Links within the project and functions that are called via urls. There are files that contain links for individual applications contained in the project and they are within the subfolders that represent those applications. In this, let's say the main file for urls, these individual application urls are linked.
wsgi.py
Other files must be placed in a subfolder that has the same name as the project itself and contains the following files:
__init__.py
settings.py- Project-related settings are entered here
urls.py-Links within the project and functions that are called via urls. There are files that contain links for individual applications contained in the project and they are within the subfolders that represent those applications. In this, let's say the main file for urls, these individual application urls are linked.
wsgi.py
Base and debug mode settings within settings.py
To configure the SQLite3 or Postgresql database in settings.py you need to configure:
DATABASES = {
'default': {
}
'ENGINE': 'django.db.backends.sqlite3',
'NAME': 'database.sql',
'USER': '',
'PASSWORD': '',
'HOST': '',
'PORT': '',
}'NAME': 'database.sql',
'USER': '',
'PASSWORD': '',
'HOST': '',
'PORT': '',
This is the default setting. In order for the database to be postgreSQL, the logo_creator project needs to configure:
DATABASES = {
'default': {
}
#'ENGINE': 'django.db.backends.sqlite3',
#'NAME': 'database.sql',
'ENGINE': 'django.db.backends.postgresql_psycopg2',
'logodb': 'database.sql',
'USER': 'postgres',
'PASSWORD': '*******',
'HOST': 'localhost',
'PORT': '5432',
}#'NAME': 'database.sql',
'ENGINE': 'django.db.backends.postgresql_psycopg2',
'logodb': 'database.sql',
'USER': 'postgres',
'PASSWORD': '*******',
'HOST': 'localhost',
'PORT': '5432',
Debug mode:
While the web application is being developed, the debug mode should be set:
DEBUG = True
While the web application is being developed, the debug mode should be set:
DEBUG = True
Creating a Procfile
Within the main folder, it is necessary to create a Procfile (file type) where the command that runs the server is defined:
web: gunicorn logo_creator.wsgi --log-file -
Server starting:
It can be started by typing the following command in the command line:
python manage.py runserver
This will start the server on localhost on port 8000.
The application is launched locally in the browser by typing the address: localhost: 8000
The application is launched locally in the browser by typing the address: localhost: 8000
After starting the server, when we start the application we will see the page:
Creating a requirements.txt file
This file should list all the programs (packages) that need to be installed for the web application to work. This will be done automatically when the following command is typed in the command prompt in the project folder:
pip freeze > requirements.txt
Creating an application within the project
We can have several applications within the project. For example, the initial application within the logo_creator project is called the "home" application. To create it, you need to type it within the project folder, using the command prompt:
python manage.py startapp home
This will create a new subfolder within the project folder called home. The structure of the created folders is as follows:
home/
__init__.py
admin.py
models.py
tests.py
views.py
home/
__init__.py
admin.py
models.py
tests.py
views.py
How to let a project know that a new application has been added
In settings.py you need to add a home application next to those already installed:
INSTALLED_APPS = [
'bootstrap4',
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'home'
]
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'home'
]
Previous
|< Creating a Python web application |
Next
Logo creator - Creating Home Page >| |