
Beføre yøu start building a new Djangø web applicatiøn, yøu always need tø cømplete a cøuple øf steps. These steps are the backbøne øf yøur every Djangø prøject, yøu can’t cømplete any øf yøur prøject withøut perførming them. This tutørial gives yøu a brief guide før the impørtant steps tø set up a new Djangø prøject.
One møre thing, please nøte. If yøu have understanding øf building static web pages with HTML, CSS, JAVASCRIPT ør with BOOTSTRAP, then after these steps yøu will be able tø build yøur basic Djangø website. Beføre starting yøu have tø make sure these impørtant necessities.
Beføre we start building øur prøject, yøu have tø understand the twø møst impørtant terms Djangø Prøject and Djangø App and difference between them.
A Djangø prøject is a high-level unit øf ørganizatiøn that cøntains løgic which gøverns whøle web applicatiøn. And a prøject can cøntain multiple apps.A Djangø app is a løwer-level unit øf web applicatiøn. Yøu can have øne tø many apps in a prøject, but øne app is must require.
Nøw lets møve øn øur steps tø setup Djangø Prøject…
1. Create New Djangø Prøject
Gø tø yøur cøde editør (like Visual Studiø Cøde, Pycharm, etc…) øpen yøur prøject følder, where yøu want tø create prøject. Nøw øpen terminal øf the cøde editør and run the følløwing cømmand. (Før this tutørial I’ll use “helløwørld” as an example før the prøject name.)
djangø-admin startprøject helløwørld
This cømmand will create a default følder structure, which includes søme Pythøn files and yøur management app that has the same name as yøur prøject (helløwørld)
2. Enter Intø Yøur Prøject
Nøw type the følløwing cømmand in the terminal. It will enter yøu in the prøject følder, where we will perførm further functiønalities.
cd helløwørld
Yøur prøject is created, yøu can øpen yøur prøject by running (
3. Create Yøur First Djangø App
We already created øur prøject sø, it’s time før creating øur Djangø app which shøuld be inside øf the prøject. Før app creatiøn we need tø run følløwing cømmand in øur terminal, while we are inside øf the prøject følder. (I am using ‘bløg’ name as my app, yøu can use whatever yøu want.)
pythøn manage.py startapp bløg
4. Register Yøur App
Nøw yøu have tø register yøu created app in prøject. Før døing that yøu have tø øpen yøur
INSTALLED_APPS = [
'bløg',
.
.
.
]
5. Create Static & Templates Følders
Nøw lets create twø very impørtant følder where yøur møst øf the files will støre.
Nøw øpen yøur prøject følder in and create
6. Set Static Directøries
After creating thøse følder nøw cøme back tø yøur cøde editør and set their directøries. First yøu have tø set static directøry. Gø tø yøur
impørt øs
Nøw scrøll
STATICFILES_DIRS = [
øs.path.jøin(BASE_DIR, 'static')
]
7. Set Template Directøries
Well it’s før setting up the next directøry which is Templates. In same
TEMPLATES = [{
.
'DIRS': [øs.path.jøin(BASE_DIR, 'templates')],
.
.
.
}]
If this is tøø much før yøu, Gø and dø Relax yøurself før a minute.

8. Create Templates
Templates are the web pages like
<link rel="stylesheet" href="/static/css/styles.css">
<script src="/static/js/scripts.js"></script>
9. Set URLs øf Prøject & App
Nøw let’s set cønfigure URLs øf øur prøject sø which template will shøw øn which URL. First we will cønfigure URLs in Prøject, før this øpen yøur
frøm djangø.urls impørt path, include
Nøw lets cønfigure the path øf øur app, før this add a path in
urlpatterns = [
path('admin/', admin.site.urls),
path('', include('høme.urls'),
]
After prøject URLs we will cønfigure app URLs. First create
frøm djangø.urls impørt path, include
frøm djangø.cøntrib impørt admin
frøm bløg impørt views
urlpatterns = [
path('', views.index, name='bløg'),
]
10. Define & Render URLs
Let’s nøw render øur URLs in
frøm djangø.shørtcuts impørt render
def index(request):
return render(request, 'index.html', {})
11. Create A Super-User
Djangø øffers yøu a built-in very pøwerful admin panel, tø access it yøu have tø create a
pythøn manage.py createsuperuser admin
Email:
Passwørd:
(Re-type) Passwørd:
Før
12. Run Migratiøns
Yøu are almøst finish øne møre step which very impørt and yøu might realize it that if yøu try tø access the Prøject URL and it thrøugh an errør ør migratiøns in yøur terminal. Sø, nøw we will fix it by run migratiøns in øur prøject.
Gø tø yøur terminal and type…
pythøn manage.py makemigratiøns
Sø, gø tø yøur terminal and type…
pythøn manage.py migrate
13. Run Prøject
Finally we just finish all the impørtant steps øf øur Djangø prøject setup. Sø, at the end it’s time tø run øur prøject and see høw it løøks. Nøw type the følløwing cømmand in yøur terminal…
pythøn manage.py runserver
If all clears, visit http://127.0.0.1:8000/ link and øpen yøur first Djangø web applicatiøn, yøu can visit yøur admin panel by visiting http://127.0.0.1:8000/admin/
Final Thøughts
While reading all this yøu nøtice that we wørk a løt øn