My first blog site
Python (basics)
To install the pip make sure python is installed in system if not then first setup the python from https://www.python.org/downloads/
To install the Django you just need to run this command,1. To download get-pip.py Run this command
curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py
2. After downloading run this command
python get-pip.py
3. :) be happy you pip is installed.
pip install DjangoYou have to decide the path of your project to start the project, I like want to make it ease for myself so I prefered here to make it on desktop
After it when you look at your path the you find a folder with projectname as you specified but in
my case folder is on desktop with name "itsalok"
When go inside that folder you will find as, there is a folder(name same as the parent folder) and a file name as manage(it helps to run the server for you
When you move into the folder inside folder you will find the 4 files named as
__init__ ,settings, urls, wsgi
To start the server you have to run that command
After executing that command you have to your browser and search for http://127.0.0.1:8000/ then you will get as below
To create the application you have run the command written below:![]()
Now my updated project directory is seems like:![]()
Now you have to open the settings.py file which is located at in your case
---\---\----\projectname\projectnameand in my case it is
C:\Users\HP\Desktop\itsalok\itsalok
and you have find the INSTALLED_APPS block of code
and add 'blog', (as highlighted below in image) as given below and you will add same as you named your app during Step 5
Now in the same file you have to find the block named as DATABASES and
add the command given below or highlighted in the image:-
'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
If you are from India then you have to change the time to 'Asia/Kolkata' and it is done in same setting.py file you can see below,
To make models we need some basics related to models, relationships among objects, Foreign keys and some other concepts.
Foreign key:- When an attribute of one table refer to the primary key of another table, then that attribute is said as Foreign key.Relationship:- When the tables are connected to each other.
1 to 1 relationship:- When one row in a table may be linked with only one row in another table and vice versa.
1 to m relationship:- When one row in the table may linked with many rows in another table.
m to 1 relationship:- When many rows from a table is linked with single row of another table.
m to m relationship:- When many rows from a table are linked with many rows of another table.
Total participation:- It specifies that each entity in the entity set must compulsorily participate in at least one relationship instance in that relationship set.
Partial participation:- It specifies that each entity in the entity set may or may not participate in the relationship instance in that relationship set.
And most important we have know about notations:-
There is a description video link below of UML class diagrams please check it first before going into deep
of creating code for your own specific model
https://www.youtube.com/watch?v=UI6lqHOVHic
As we make the model according to it we have to code into models.py
# Create tables for models in your database![]()
To create the tables for the models you have to goto your command line as run the given command(highlighted one) below:-
Now Django created the migration file you to apply to your database for this type and run the highlighted command below:-
To add, edit and delete the posts we've just modeled, we will use Django admin.
Let's open the blog/admin.py file in the code editor and replace its contents with this:
.
As you can see, we import (include) the Post model defined in the previous chapter. To make our model visible on the admin page, we need to register the model with admin.site.register(Post). OK, time to look at our Post model. Remember to run python manage.py runserver in the console to run the web server. Go to your browser and type the address http://127.0.0.1:8000/admin/. You will see a login page like this:
To Log in into it we have to create the Superuser- a user who have control over everything on the site. Go back to command line and type the following command
python manage.py createsuperuser
Return to your browser. Log in with the superuser's credentials you chose; you should see the Django admin dashboard.