0% found this document useful (0 votes)
203 views8 pages

Django Portfolio Project

This document provides instructions for creating a Django portfolio project. It includes commands for installing Django, starting a project and app, creating models and migrations, setting up the admin site, and rendering pages. Key steps include using pip to install Django, running django-admin commands to start the project and apps, defining models, migrating the database, registering models in the admin, and linking views and templates.

Uploaded by

Subavani
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
203 views8 pages

Django Portfolio Project

This document provides instructions for creating a Django portfolio project. It includes commands for installing Django, starting a project and app, creating models and migrations, setting up the admin site, and rendering pages. Key steps include using pip to install Django, running django-admin commands to start the project and apps, defining models, migrating the database, registering models in the admin, and linking views and templates.

Uploaded by

Subavani
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8

Django Portfolio Project

Things to note in whole document

Terminal Command: Terminal Command

While install using pip we need internet connectivity

In PyCharm Create new project [ file -> newfile -> ( provide file name) Create ]

Created by: Dinesh Kumar


Goto Terminal:

In Terminal provide these below commands to start with Django

Pip install Django - to install Django

django-admin startproject portfolio , command to start project

cd portfolio ,to move to the manage.py location

python manage.py runserver ,to run server use cmd,

Go to ip which showing or type localhost:8000 this url manually in any brower, if you see the below
image then its installed successfully.

To close server press Ctrl + C

Created by: Dinesh Kumar


django-admin startapp jobs , give command to create app named jobs

Inside settings.py add our app in installed app list

In settings.py before adding

After adding our app jobs, ref image

Add urls in url.py inside project folder(portfolio)

Inside jobs->views.py add this homepage function

Created by: Dinesh Kumar


Inside jobs (app folder), create a new folder templates, inside templates create another new folder
jobs

Inside templates -> jobs, Create homepage.html file and type <h1>Login360</h1>

Now run server using command, python manage.py runserver

Give url as 127.0.0.1:8000/dinesh or localhost:8000/dinesh, it will rendered homepage.html for this


url request

Model: It’s a python class that used to create tables in our database.

Going to Create table named Job with two columns image (ImageField) and Summary (CharField).

Inside jobs -> models.py

Pip install pillow , to work with images

Created by: Dinesh Kumar


Django has sqlite3 database as default DB, which was available within Django itself.

So, no configuration changes required to store sqlite3 DB, so skip this page if you going to work on
default sqlite3 DB

But to work with different database engine we need to install that database engine and need to
config our settings.py, refer below details to install and config postgresql

Procedure to Install Postgresql

Go to https://www.enterprisedb.com/downloads/postgres-postgresql-downloads

1. Choose PostreSQL latest version and Windows x86-64 and click Download Now.
2. Install the downloaded file
3. Choose a password
4. Keep the default port of 5432.
5. Uncheck the Stack Builder option and click Finish
6. In your Windows search bar, search for pgadmin and launch it.
7. Right-click PostgreSQL in Servers and choose Connect
8. Right-click Databases and choose Create-> Database…

9. Add the name portfoliodb and set owner to postgres

Inside settings.py Config our installed postgresql database as below code

In python terminal give the below command to work with postgresql in python.

pip install psycopg2

Created by: Dinesh Kumar


Once database is ready, we need to makemigrations and migrate

makemigrations: Based on our model.py, it will create .py file inside migrations folder,

migrate: To create/update our Database, based on the created .py file in migrations folder.

python manage.py makemigrations

python manage.py migrate

It will automatically create the below 0001_initial.py and make table as we mentioned.

Create super user to work in admin site:

In terminal type below commands to create super user.

python manage.py createsuperuser

Give username, skip email by pressing Enter. Provide password for admin site login

python manage.py runserver

give url as http://127.0.0.1:8000/admin (or) localhost:8000/admin

then give the credential and login

To include our model Job in admin site

Inside jobs -> admin.py

Created by: Dinesh Kumar


Then login to admin site and add few jobs

To add our Job model in views.py, inside views.py type below code.

Then in homepage.html

Then run server using python manage.py runserver , you will see added job summary there.

To make homage to show in initial url , we need to change the url patterns as below in urls.py
(highlighted text doesn’t have any space inbetween)

Created by: Dinesh Kumar


Now when you run server, homepage will open at initial itself, like below.

Procedure to reset migration/delete migration: (when migrations got corrupted due to some
unnecessary change, you can use this)

1. Delete your migrations folder


2. In query editor execute the below query
DELETE FROM django_migrations WHERE app = <your app name>
You could alternatively just truncate this table.
3. python manage.py makemigrations
if it doesn’t work, then try with app name
python manage.py makemigrations <your app name>
4. python manage.py migrate

Created by: Dinesh Kumar

You might also like