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: code_editor/README.md
+2-2Lines changed: 2 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -4,7 +4,7 @@ You're about to write your first line of code, so it's time to download a code e
4
4
5
5
There are a lot of different editors and it largely boils down to personal preference. Most Python programmers use complex but extremely powerful IDEs (Integrated Development Environments), such as PyCharm. As a beginner, however - that's probably less suitable; our recommendations are equally powerful, but a lot more simple.
6
6
7
-
Our suggestions are below, but feel free to ask your coach what their preference is - it'll be easier to get help from them.
7
+
Our suggestions are below, but feel free to ask your coach what their preferences are - it'll be easier to get help from them.
8
8
9
9
## Gedit
10
10
@@ -14,7 +14,7 @@ Gedit is an open-source, free editor, available for all operating systems.
14
14
15
15
## Sublime Text 2
16
16
17
-
Sublime Text is a very popular editor with a free evaluation period. It's easy to install and use, and available for all operating systems.
17
+
Sublime Text is a very popular editor with a free evaluation period. It's easy to install and use, and it's available for all operating systems.
Copy file name to clipboardExpand all lines: css/README.md
+11-8Lines changed: 11 additions & 8 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -39,8 +39,9 @@ CSS is a static file, so in order to customize CSS, we need to first configure s
39
39
40
40
First, we need to create a directory to store our static files in. Go ahead and create a directory called `static` inside your `djangogirls` directory.
41
41
42
-
static
43
-
manage.py
42
+
djangogirls
43
+
├─── static
44
+
└─── manage.py
44
45
45
46
Open up the `mysite/settings.py` file, scroll to the bottom of it and add the following lines:
46
47
@@ -55,8 +56,8 @@ This way Django will know where to find your static files.
55
56
Let's create a CSS file now, to add your own style to your web-page. Create a new directory called `css` inside your `static` directory. Then create a new file called `blog.css` inside this `css` directory. Ready?
56
57
57
58
static
58
-
└───css
59
-
blog.css
59
+
└───css
60
+
blog.css
60
61
61
62
Time to write some CSS! Open up the `static/css/blog.css` file in your code editor.
62
63
@@ -72,7 +73,7 @@ In your `static/css/blog.css` file you should add following code:
72
73
73
74
`h1 a` is a CSS Selector. Any `a` element inside of an `h1` element (i.e. when we have in code something like: `<h1><a href="">link</a></h1>`) is the tag we're applying our styles to, and we're telling it to change its color to `#FCA205`, which is orange. Of course, you can put your own color here!
74
75
75
-
In a CSS file we determine styles for elements in the HTML file. The elements are identified by the element name (i.e. `a`, `h1`, `body`), the element class or the element id. Class and id are names you give the element by yourself. Classes define groups of elements, and ids point to specific elements. For example, the following tag may be identified by CSS using the tag name `a`, the class `external_link`, or the id `link_to_wiki_page`:
76
+
In a CSS file we determine styles for elements in the HTML file. The elements are identified by the element name (i.e. `a`, `h1`, `body`), the attribute `class` or the attribute `id`. Class and id are names you give the element by yourself. Classes define groups of elements, and ids point to specific elements. For example, the following tag may be identified by CSS using the tag name `a`, the class `external_link`, or the id `link_to_wiki_page`:
Copy file name to clipboardExpand all lines: django_admin/README.md
+2-2Lines changed: 2 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -11,7 +11,7 @@ Let's open the `blog/admin.py` file and replace its content with this:
11
11
12
12
As you can see, we import (include) the Post model defined in the previous chapter. To make our model visible on the admin page, we need to register the model with `admin.site.register(Post)`.
13
13
14
-
Ok, time to look at our Post model. Remember to run `python manage.py runserver` in the console to run the web server. Go to the browser and type the address:
14
+
OK, time to look at our Post model. Remember to run `python manage.py runserver` in the console to run the web server. Go to the browser and type the address:
15
15
16
16
http://127.0.0.1:8000/admin/
17
17
@@ -25,7 +25,7 @@ You should use the username and password you chose when you were creating a data
25
25
26
26
Go to Posts and experiment a little bit with it. Add five or six blog posts. Don't worry about the content - you can simply copy-paste some text from this tutorial as your posts' content to save time :).
27
27
28
-
Make sure that at least two or three posts (but not all) have a publish date set. It will be helpful later.
28
+
Make sure that at least two or three posts (but not all) have the publish date set. It will be helpful later.
Copy file name to clipboardExpand all lines: django_models/README.md
+15-14Lines changed: 15 additions & 14 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -57,24 +57,25 @@ A model in Django is a special kind of object - it is saved in the `database` (d
57
57
58
58
### Creating an application
59
59
60
-
To keep everything tidy, we will create a separate application inside our project. It is very nice to have everything organized from the very beginning. To create an application we need to run in the console (from `djangogirls` directory where `manage.py` file is)`python manage.py startapp blog`.
60
+
To keep everything tidy, we will create a separate application inside our project. It is very nice to have everything organized from the very beginning. To create an application we need to run the following command in the console (from `djangogirls` directory where `manage.py` file is):
61
61
62
62
(myvenv) ~/djangogirls$ python manage.py startapp blog
63
63
64
64
You will notice that a new `blog` directory is created and it contains a number of files now. Our directories and files in our project should look like this:
65
65
66
-
mysite
67
-
├── __init__.py
68
-
├── settings.py
69
-
├── urls.py
70
-
├── wsgi.py
71
-
manage.py
72
-
blog
73
-
├── __init__.py
74
-
├── admin.py
75
-
├── models.py
76
-
├── tests.py
77
-
└── views.py
66
+
djangogirls
67
+
├── mysite
68
+
| __init__.py
69
+
| settings.py
70
+
| urls.py
71
+
| wsgi.py
72
+
├── manage.py
73
+
└── blog
74
+
__init__.py
75
+
admin.py
76
+
models.py
77
+
tests.py
78
+
views.py
78
79
79
80
After creating an application we also need to tell Django that it should use it. We do that in the file `mysite/settings.py`. We need to find `INSTALLED_APPS` and add a line `blog` just above `)`. We should also add the `mysite` application (which was created for us when we started a new project in the last chapter). So the final product should look like this:
80
81
@@ -91,7 +92,7 @@ After creating an application we also need to tell Django that it should use it.
91
92
92
93
### Creating a blog post model
93
94
94
-
In a file `models.py` we define all objects called `Models` - this is a place in which we will define our blog post.
95
+
In the `models.py` file we define all objects called `Models` - this is a place in which we will define our blog post.
95
96
96
97
Let's open `blog/models.py`, remove everything from it and write code like this:
Copy file name to clipboardExpand all lines: django_orm/README.md
+5-5Lines changed: 5 additions & 5 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -4,7 +4,7 @@ We have different pieces in place: the `Post` model is defined in `models.py`, w
4
4
5
5
This is exactly what *views* are supposed to do: connect models and templates. In our `post_list`*view* we will need to take models we want to display and pass them to the template. So basically in a *view* we decide what (model) will be displayed in a template.
6
6
7
-
Ok, so how we will achieve it?
7
+
OK, so how we will achieve it?
8
8
9
9
We need to open our `blog/views.py`. So far `post_list`*view* looks like this:
10
10
@@ -13,18 +13,18 @@ We need to open our `blog/views.py`. So far `post_list` *view* looks like this:
13
13
def post_list(request):
14
14
return render(request, 'blog/post_list.html', {})
15
15
16
-
Remember when we talked about including code written in different files? Now is a moment when we have to include the model we have written in `models.py`. We will add this line `from .models import Post` like this:
16
+
Remember when we talked about including code written in different files? Now it is the moment when we have to include the model we have written in `models.py`. We will add this line `from .models import Post` like this:
17
17
18
18
from django.shortcuts import render
19
19
from .models import Post
20
20
21
21
Dot after `from` means *current directory* or *current application*. Since `views.py` and `models.py` are in the same directory we can simply use `.` and the name of the file (without `.py`). Then we import the name of the model (`Post`).
22
22
23
-
But what's next? To take actual blog posts from `Post` model we need something called a `Queryset`.
23
+
But what's next? To take actual blog posts from `Post` model we need something called `Queryset`.
24
24
25
25
## Queryset
26
26
27
-
So now we are interested in a list of blog posts, right? But all we have is model`Post`. A Queryset will give us a collection we are looking for. All we need to do is use:
27
+
So now we are interested in a list of blog posts, right? But all we have is the`Post` model. A Queryset will give us a collection we are looking for. All we need to do is use:
28
28
29
29
Post.objects.all()
30
30
@@ -52,7 +52,7 @@ Now we put this piece of code inside the `post_list` file, by adding it to the f
52
52
return render(request, 'blog/post_list.html', {})
53
53
54
54
Please note that we create a *variable* for our queryset: `posts`. Treat this as the name of our queryset. From now on we can refer to it by this name.
55
-
The last missing part is to pass the `posts` queryset to the template (we will cover how to display it in a next chapter).
55
+
The last missing part is passing the `posts` queryset to the template (we will cover how to display it in a next chapter).
56
56
57
57
In the `render` function we already have parameter with `request` (so everything we receive from the user via the Internet) and a template file `'blog/post_list.html'`. The last parameter, which looks like this: `{}` is a place in which we can add some things for the template to use. We need to give them names (we will stick to `'posts'` right now :)). It should look like this: `{'posts': posts}`. Please note that the part before `:` is wrapped with quotes `''`.
Copy file name to clipboardExpand all lines: django_start_project/README.md
+5-5Lines changed: 5 additions & 5 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -13,9 +13,9 @@ The first step towards creating it is starting a new Django project. Basically,
13
13
14
14
The names of some files and directories are very important for Django. You should not rename the files that we are about to create. Moving them to a different place is also not a good idea. Django needs to maintain a certain structure in order to be able to find important things.
15
15
16
-
In console you should run (remember that you don't type `(myvenv) ~/djangogirls$`, ok?):
16
+
In console you should run (remember that you don't type `(myvenv) ~/djangogirls$`, OK?):
17
17
18
-
> Remember to run everything in the virtualenv. If you don't see a prefix `(myvenv)` in your console you need to activate your virtualenv. We explained how to that in __Django installation__ chapter in __Working with virtualenv__ part.
18
+
> Remember to run everything in the virtualenv. If you don't see a prefix `(myvenv)` in your console you need to activate your virtualenv. We explained how to do that in the __Django installation__ chapter in the__Working with virtualenv__ part.
19
19
20
20
Run on Windows:
21
21
@@ -27,8 +27,8 @@ or on Linux or Mac OS:
27
27
28
28
`django-admin.py` is a script that will create the directories and files for you. You should now have a directory structure which looks like this:
29
29
30
-
manage.py
31
-
│
30
+
djangogirls
31
+
├───manage.py
32
32
└───mysite
33
33
settings.py
34
34
urls.py
@@ -48,7 +48,7 @@ Let's ignore the other files for now - we won't change them. The only thing to r
48
48
49
49
Let's make some changes in `mysite/settings.py`. Open the file using the code editor you installed earlier.
50
50
51
-
It would be nice to have the correct time on our website. Go to http://en.wikipedia.org/wiki/List_of_tz_database_time_zones and copy your relevant time zone (TZ). (eg. `Europe/Berlin` )
51
+
It would be nice to have the correct time on our website. Go to http://en.wikipedia.org/wiki/List_of_tz_database_time_zones and copy your relevant time zone (TZ). (eg. `Europe/Berlin` )
52
52
53
53
You should find lines that contain `USE_TZ` and `TIME_ZONE` and modify them to look like this, substituting `Europe/Berlin` with your relevant time zone:
Copy file name to clipboardExpand all lines: django_templates/README.md
+3-3Lines changed: 3 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -10,7 +10,7 @@ __Django template tags__ allow us to transfer Python-like things into HTML, so y
10
10
11
11
## Display post list template
12
12
13
-
In the previous chapter we gave our template a list of posts in a`posts` variable. Now we will display it in HTML.
13
+
In the previous chapter we gave our template a list of posts in the`posts` variable. Now we will display it in HTML.
14
14
15
15
To print a variable in Django template, we use double curly brackets with the variable's name inside, like this:
16
16
@@ -24,7 +24,7 @@ As you can see, all we've got is this:
24
24
25
25
[<Post: My second post>, <Post: My first post>]
26
26
27
-
This means that Django understand it as a list of objects. Remember from __Introduction to Python__ how we can display lists? Yes, with for loops! In a Django template, you do them this way:
27
+
This means that Django understand it as a list of objects. Remember from __Introduction to Python__ how we can display lists? Yes, with the for loops! In a Django template, you do them this way:
28
28
29
29
{% for post in posts %}
30
30
{{ post }}
@@ -34,7 +34,7 @@ Try this in your template.
34
34
35
35

36
36
37
-
It works! But we want them to be displayed in a way we created earlier in the __Introduction to HTML__ chapter - like the static posts we put there before. You can mix HTML and template tags. Our `body` will look like this:
37
+
It works! But we want them to be displayed like the static posts we created earlier in the __Introduction to HTML__ chapter. You can mix HTML and template tags. Our `body` will look like this:
Copy file name to clipboardExpand all lines: django_urls/README.md
+2-2Lines changed: 2 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -31,11 +31,11 @@ As you can see, Django already put something here for us.
31
31
32
32
Lines that start with `#` are comments - it means that those lines won't be executed by Python. Pretty handy, right?
33
33
34
-
The admin url, which you visited in previous chapter is already here:
34
+
The admin URL, which you visited in previous chapter is already here:
35
35
36
36
url(r'^admin/', include(admin.site.urls)),
37
37
38
-
It means that for every url that starts with `admin/` Django will find a corresponding *view*. In this case we're including a lot of admin urls so it isn't all packed into this small file -- it's more readable and cleaner.
38
+
It means that for every URL that starts with `admin/` Django will find a corresponding *view*. In this case we're including a lot of admin URLs so it isn't all packed into this small file -- it's more readable and cleaner.
Copy file name to clipboardExpand all lines: how_internet_works/README.md
+2-2Lines changed: 2 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,6 +1,6 @@
1
1
# How the Internet works
2
2
3
-
*This chapter is inspired by a talk "How the Internet works" by Jessica McKellar (http://web.mit.edu/jesstess/www/).*
3
+
> This chapter is inspired by a talk "How the Internet works" by Jessica McKellar (http://web.mit.edu/jesstess/www/).
4
4
5
5
We bet you use the Internet every day. But do you actually know what happens when you type an address like http://djangogirls.org into your browser and press 'Enter'?
6
6
@@ -13,7 +13,7 @@ follow its instructions and present all these files that your website is made of
13
13
As with every file, we need to store HTML files somewhere on a hard disk. For the Internet, we use special, powerful computers called *servers*. They don't have
14
14
a screen, mouse or a keyboard, because their main purpose is to store data and serve it. That's why they're called *servers* -- because they *serve* you data.
15
15
16
-
Ok, but you want to know how the Internet looks like, right?
16
+
OK, but you want to know how the Internet looks like, right?
0 commit comments