You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: database/README.md
+12-7Lines changed: 12 additions & 7 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,8 +1,8 @@
1
1
# Database
2
2
3
-
Most of web application have their own database. A database is a collection of data. This is a place in which you will store all information about users, all your blog post texts, etc..
3
+
Most of web applications have their own database. A database is a collection of data. This is a place in which you will store all information about users, all your blog post texts, etc..
4
4
5
-
We will be using a PostgreSQL database to store our data. It would be easier to just use a default Django database called sqlite, but it's not good for a production use. If you want to have your application available in the Internet, not only your computer, you will need PostgreSQL.
5
+
We will be using a PostgreSQL database to store our data. It would be easier to use a default Django database called *sqlite*, but it's not good for a production use (by *production* we mean: real, running websites). If you want to have your application available in the Internet, not only on your computer, you will need PostgreSQL.
6
6
7
7
# PostgreSQL installation
8
8
@@ -24,7 +24,7 @@ Of course, installation depends on Linux distribution. We've added most popular
@@ -34,9 +34,10 @@ Go to your console and run following command:
34
34
35
35
# Create database
36
36
37
-
Now we need to create our database user and our first database!
37
+
Now we need to create our database user and our first database. You can add many databases in PostgreSQL, so if you have more than one website, you should have a separate database for each one!
38
38
39
-
First, let's make our console into postgres mode:
39
+
First, let's make our console into postgres mode by typing `psql`. Remember the part about console?
40
+
>On Mac OS X you can do this by launching the `Terminal` application (it's in Applications → Utilities). On Windows you need to go to Start menu → All Programs → Accessories → Command Prompt. On Linux, it's probably under Applications → Accessories → Terminal.
40
41
41
42
$ psql
42
43
psql (9.3.4)
@@ -48,11 +49,15 @@ Our `$` now changed into `#`, it means that we're now giving commands to Postgre
48
49
# CREATE USER name;
49
50
CREATE ROLE
50
51
51
-
Of course, replace `name` with your own name. Now it's time for a database for your Django project:
52
+
Of course, replace `name` with your own name. Remember that you should not use diacritic letters and whitespaces, i.e. `bożena maria` is invalid! You need to transform it into `bozena_maria`.
53
+
54
+
Now it's time to create a database for your Django project:
52
55
53
56
# CREATE DATABASE djangogirls OWNER name;
54
57
CREATE DATABASE
55
58
56
-
Awesome! All ready.
59
+
Remember to replace `name` with the name you've chosen (i.e. `bozena_maria`).
Copy file name to clipboardExpand all lines: django/README.md
+6-6Lines changed: 6 additions & 6 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -4,23 +4,23 @@ Django (_/ˈdʒæŋɡoʊ/ jang-goh_) is a free and open source web application f
4
4
5
5
You see, when you're building a website, you always need a similiar set of components: a way to handle user authentication (signing up, signing in, signing out), management panel for your website, forms, uploading files, etc.
6
6
7
-
Luckily for you other people long ago noticed that web developers face similar problems when building a new site, so they teamed up and created frameworks (Django is one of them) that gives you ready components you can use.
7
+
Luckily for you other people long ago noticed that web developers face similar problems when building a new site, so they teamed up and created frameworks (Django is one of them) that give you ready components you can use.
8
8
9
9
Frameworks exist to save you from having to re-invent the wheel and help alleviate some of the overhead when you’re building a new site.
10
10
11
11
## Why do you need a framework?
12
12
13
13
To understand what Django actually is for, we need a closer look at the servers. First thing is that the server needs to know that you want it to serve you a webpage.
14
14
15
-
Imagine a mailbox (port) which is monitored for incoming letters (requests). It is done by a web server. The web server also sends the response with a webpage. But when you want to send something, you need to have some content. And Django is something that helps you create the content.
15
+
Imagine a mailbox (port) which is monitored for incoming letters (requests). It is done by a web server. The web server also sends a response with a webpage. But when you want to send something, you need to have some content. And Django is something that helps you create the content.
16
16
17
-
## What happen when someone request a website from your server?
17
+
## What happen when someone requests a website from your server?
18
18
19
-
When a request comes to a web server it's passed to Django which tries to figure out what actually is requested. It takes a webpage address used and tries to figure out what to do. This part is done by Django's urlresolver (Note that a website address is called URL - Uniform Resource Locator, so the name 'urlresolver' makes sense). It is not very smart here - it takes a list of patterns and tries to match the URL. Django checks patterns from top to the bottom and if something is matched then Django passes the request to the associated function called view.
19
+
When a request comes to a web server it's passed to Django which tries to figure out what actually is requested. It takes a webpage address first and tries to figure out what to do. This part is done by Django's urlresolver (Note that a website address is called URL - Uniform Resource Locator, so the name *urlresolver* makes sense). It is not very smart - it takes a list of patterns and tries to match the URL. Django checks patterns from top to the bottom and if something is matched then Django passes the request to the associated function (which is called *view*).
20
20
21
-
Imagine a postman with a letter who is walking down the street and checks each house number with the one on the letter. If it matches, they put the letter there.
21
+
Imagine a postman with a letter. She is walking down the street and checks each house number with the one on the letter. If it matches, they put the letter there. This is how the urlresolver works!
22
22
23
-
In the 'view' all interesting things are done: we can look at the database to look for some information to return it to the user. Maybe the user asked to change something in the data? Like a letter saying "Please change description of my job title." - the view can check if you are allowed to do that, then update the job title for you and send back a message: "Done!". Then the view generates a response and Django can send it to the user's web browser.
23
+
In the *view* function all interesting things are done: we can look at a database to look for some information. Maybe the user asked to change something in the data? Like a letter saying "Please change description of my job." - the *view* can check if you are allowed to do that, then update the job description for you and send back a message: "Done!". Then the *view* generates a response and Django can send it to the user's web browser.
24
24
25
25
Of course, the description above is a little bit simplified, but you don't need to know all the technical things yet. Knowing a general idea is enough.
Copy file name to clipboardExpand all lines: python_introduction/README.md
+19-19Lines changed: 19 additions & 19 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -29,7 +29,7 @@ Nice! See how the answer popped out? Python knows math! You could try other comm
29
29
-`5 - 1`
30
30
-`40 / 2`
31
31
32
-
Have fun with this for a little while and then get back here :)
32
+
Have fun with this for a little while and then get back here :).
33
33
34
34
As you can see, Python is a great calculator. If you're wondering what else you can do...
35
35
@@ -74,18 +74,18 @@ Ok, enough of strings. So far you've learned about:
74
74
-__numbers and strings__ - in Python it's math and text objects
75
75
-__methods__ - are actions in Python. You've used both English-language methods (upper, len) and symbolic ones (+, *).
76
76
77
-
That's the basic of every programming language you learn. Ready for something harder? I bet you are!
77
+
That's the basic of every programming language you learn. Ready for something harder? We bet you are!
78
78
79
79
## Errors
80
80
81
-
Let's try something. Can we know the length of a number, the same way we learn about the length of our name? Try typing `len(304023)` and hit Enter:
81
+
Let's try something. Can we get a length of a number, the same way we learn about the length of our name? Try typing `len(304023)` and hit Enter:
82
82
83
83
>>> len(304023)
84
84
Traceback (most recent call last):
85
85
File "<stdin>", line 1, in <module>
86
86
TypeError: object of type 'int' has no len()
87
87
88
-
We got our first error! It says that objects of type "int" (integers, whole numbers) don't have a length. So what can we do now? Maybe we can write our number as string? Strings have length, right?
88
+
We got our first error! It says that objects of type "int" (integers, whole numbers) don't have a length. So what can we do now? Maybe we can write our number as a string? Strings have length, right?
89
89
90
90
>>> len(str(304023))
91
91
6
@@ -112,7 +112,7 @@ As you've noticed, your program didn't return anything like it did before. How d
112
112
>>> name
113
113
'Ola'
114
114
115
-
Yikes! Your first variable :) You can always change what it is:
115
+
Yikes! Your first variable :)! You can always change what it is:
116
116
117
117
>>> name = "Sonja"
118
118
>>> name
@@ -134,7 +134,7 @@ Play with this for a while and see what you can do!
134
134
135
135
## Lists
136
136
137
-
Beside strings and integers, Python has all sorts of different types of objects. Now we're going to introduce another one called __lists__. List is the exact thing you think about now: object that is a list of objects :)
137
+
Beside strings and integers, Python has all sorts of different types of objects. Now we're going to introduce one called __list__. List is the exact thing you think about now: object that is a list of objects :)
138
138
139
139
Go ahead and create a list:
140
140
@@ -145,7 +145,7 @@ Yes, it's empty. Not very useful, right? Let's create a list of lottery numbers.
145
145
146
146
>>> lottery = [3, 42, 12, 19, 30, 59]
147
147
148
-
All right, we have a list! What can we do with it? Let's see how many lottery numbers there is in a list. Do you have an idea which method you should use for that? You know this already!
148
+
All right, we have a list! What can we do with it? Let's see how many lottery numbers there are in a list. Do you have an idea which method you should use for that? You know this already!
149
149
150
150
>>> len(lottery)
151
151
6
@@ -167,13 +167,13 @@ Maybe we want to reverse the order? Let's do that!
167
167
>>> print(lottery)
168
168
[59, 42, 30, 19, 12, 3]
169
169
170
-
It worked! If you want to add something to the list, you can do this by typing this command:
170
+
Easy, right? If you want to add something to the list, you can do this by typing this command:
171
171
172
172
>>> lottery.append(199)
173
173
>>> print(lottery)
174
174
[59, 42, 30, 19, 12, 3, 199]
175
175
176
-
If you want to only read the first number, you can do this by using index. The first objects of list is an object number 0, next one is 1, and so on. Try this:
176
+
If you want to read only the first number, you can do this by using index. The first object of the list is an object number 0, next one is 1, and so on. Try this:
177
177
178
178
>>> print(lottery[0])
179
179
59
@@ -268,7 +268,7 @@ Practice and have fun with Boolean by trying to run following commands:
268
268
-`True or 1 == 1`
269
269
-`1 != 2`
270
270
271
-
Congrats! You can know move on to the essence of programming:
271
+
Congrats! You can now move on to the essence of programming:
272
272
273
273
## If...elif...else
274
274
@@ -288,7 +288,7 @@ So far nothing has happened, as evidenced by dots `...` instead of incentives `>
288
288
^
289
289
IndentationError: expected an indented block
290
290
291
-
Well...something went wrong. Python needs to know whether the instruction we have written is a continuation of `if` or it is the next instruction not covered by the condition. To this purpose we need to indent our code:
291
+
Well...something went wrong! Python needs to know whether the instruction we have written is a continuation of `if` or it is the next instruction not covered by the condition. We need to indent our code to make it work:
292
292
293
293
>>> if 3 > 2:
294
294
... print('It works!')
@@ -343,14 +343,14 @@ Time for the last part of this chapter!
343
343
344
344
## Methods (functions)
345
345
346
-
Remember about methods like `len` that you can execute in Python? Well, good news, you will learn how to write you own functions now!
346
+
Remember about methods like `len` that you can execute in Python? Well, good news, you will learn how to write your own functions now!
347
347
348
348
A function is a set of instructions that Python should execute. Each function in Python starts with the keyword `def`, has a name and can have some parameters. Let's start with an easy one:
349
349
350
350
>>> def hi():
351
351
...
352
352
353
-
As you can see, there are the dots again! This means that nothing has really happenned yet.. and yes, we need to do a `TAB` before giving our instructions:
353
+
As you can see, there are the dots again! This means that nothing has really happenned yet... and yes, we need to do a `TAB` before giving our instructions:
354
354
355
355
>>> def hi():
356
356
... print('Hi there!')
@@ -363,9 +363,9 @@ Ok, our first function is ready! Let's execute it:
363
363
Hi there!
364
364
How are you?
365
365
366
-
Great! You're now a programmer, congratulate yourself :)
366
+
Great! You're now a programmer, congratulate yourself :)!
367
367
368
-
That was easy, so let's build our first function with parameters. We will use previous example with names:
368
+
That was easy! Let's build our first function with parameters. We will use the previous example with names:
369
369
370
370
>>> def hi(name):
371
371
...
@@ -403,19 +403,19 @@ Let's call the function now:
403
403
>>> hi("Rachel")
404
404
Hi Rachel!
405
405
406
-
Congrats! :)
406
+
Congratulations! You just learned how to write functions :)!
407
407
408
408
## Loops
409
409
410
410
That's the last part already. That was quick, right?:)
411
411
412
-
As we mentioned, programmers are lazy, they don't like to repeat themselves. Programming is all about automating things, so we don't want to greet every girl by their name manually, right? That's where loops come handy.
412
+
As we mentioned, programmers are lazy, they don't like to repeat themselves. Programming is all about automating things, so we don't want to greet every girl by their name manually, right? That's where loops come in handy.
413
413
414
414
Remember lists yet? Let's do a list of all the girls:
0 commit comments