Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

Django Documentation

Download as pdf or txt
Download as pdf or txt
You are on page 1of 2

Step 1:- Create Project & Install Package

. Python
. Django

Step 2:- To start the project command


. django-admin startproject smart

Step 3:- Create virtual env & cd to smart in terminal

Step 4:- Create app command


. python manage.py startapp barhalfshaft

Step 5:- Start Django server


. python manage.py runserver

Step 6:- Go to barhalfshaft views.py file & create def function & import package
. HttpResponse

Step 7:- Create urls.py file in barhalfshaft & create path in urls.py

Step 8:- Update path in main project(smart)in urls.py & import include

Step 9:- Go to barhalfshaft & create templates folder. In template folder create new folder
barhalfshaft

Step 10:- Go to smart folder settings.py file & add some changes in INSTALLED_APPS add
'barhalfshaft',

Step 11:- Go to template folder & create HTML file

Step 12:- Create static folder in barhalfshaft & create new folder barhalfshaft

Step 13:- Load static file command in HTML file


{% load static %}
<a href="{%static 'barhalfshaft\mystatic.txt' %}">Click Me</a>

Step 14:- Create Database


1. First migrate use command — python manage.py migrate
2. After migration go to models.py & create class function
3. In settings.py go to INSTALLED_APPS to make changes first clear app name
(‘barhalfshaft’) and add appname.apps.functname(apps.py function name)
('barhalfshaft.apps.BarhalfshaftConfig'),
4. Check if theres a error by running server
5. After that make migrations — python manage.py makemigrations
6. Then again migrate, — python manage.py migrate
7. Creating super user db — python manage.py createsuperuser
8. Username: rohit
9. Email address: xyz@gmail.com
10. Password: 1234
11. Start server & go to /admin. Login
12. Go to admin.py to register your model

Step 15:- Adding Images & Changing Models In Django


1. Go to models.py and add image
2. Install pillow "python -m pip install Pillow"
3. image = models.ImageField(upload_to="barhalfshaft/images")
4. After that make migrations — python manage.py makemigrations
5. To make changes in db use command — python manage.py migrate

Step 16:-

You might also like