1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
|
Tutorial: Creating Your First Django Project
=====================================
[Demonstration time: 7 mins 30 secs (0.812 ~ 81%) | Total time: 9 mins 11 s]
-------------
Slide 1 [00:08 | 00:08]
-------------
Title Slide: ** Creating a Django Project **
Slide 2 [00:12 | 00:20]
--------------
**Learning Objectives**
In this tutorial, we will learn to;
- Create a django project
- Initialize a django app
Slide 3 [00:11 | 00:31]
---------------
**System Requirements**
- Ubuntu 16.10
- Python 3.5 or higher version
- python3.4-venv
Slide 4 [00:15 | 00:46]
---------------
**Pre-requisites**
In order to follow this tutorial, you need to know;
- how to use a virtual environment
- how to install django
- If not, see the relevant django tutorial on http://spoken-tutorial.org
Demonstration: [01:30 | 2:16]
------------
- Revisit the virtual environment created in previous tutorial.
- Activate the virtual environment
- Create a new directory
- mkdir myproject
- Go to the directory
- cd myproject
- Run the command
- *django-admin startproject mysite*
- This will create a django project 'mysite'
Demonstration: [02:00 | 4:16]
-------------
- A Django project:
- is a collection of settings for an instance of Django
- includes;
- database configuration
- Django-specific options
- Application-specific settings
**(Not for narration) Note: For this demonstration we can navigate through project files and explain them **
Slide 5: [00:05 | 04:21]
-------------
- You will see such a File structure
myproject/
|-> manage.py
`-> mysite/
|-> __init__.py
|-> settings.py
|-> urls.py
`-> wsgi.py
Demonstration [01:30 | 05:51]
---------------
- Now let us run the django server and check;
- *python manage.py runserver*
- You will see that the server is running at the address shown.
- Go to the address via web browser
- We see the django's index page- "It works"
- Here we can see the command to create an app in django.
Slide [00:10 | 06:01]
-----------
**Initializing a Django App**
- A Django project typically contains one or more apps
- A Django app performs a particular task
- Let us create a blogging app called 'blog'
Demonstration [01:30 | 07:31]
--------------
- Run the command;
- *python manage.py startapp blog*
This creates an app 'blog'
- A new directory 'blog' is created.
- Execute *cd blog/*
- You will see the file structure(This can be in slide or terminal)
blog/
|-> __init__.py
|-> admin.py
|-> apps.py
|-> migrations/
`-> __init__.py
|-> models.py
|-> tests.py
`-> views.py
- Return to the parent directory
- *cd ..*
Demonstration [01:00 | 08:31]
------------
** Adding the app to the settings file**
- For the project to detect an app, we need to add the app name to settings.py
- Open the *settings.py* file
- Go to *INSTALLED_APPS* and add *'blog.apps.BlogConfig',* to the list so it should now look like this;
INSTALLED_APPS = [
'blog.apps.BlogConfig',
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
]
- So now our app will be recognized by our project.
- In the next tutorial we will see how to build the Blog app
Slide 13 [00:10 | 08:41]
---------------
** Assignment **
- Create a new project and app
** Followed by standard concluding slides ** [00:30 | 09:11]
|