Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Editorial tweaks + how to print a given element of a dictionary #102

Merged
merged 2 commits into from
Aug 8, 2014
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions code_editor/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ You're about to write your first line of code, so it's time to download a code e

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.

Our suggestions are below, but feel free to ask your coach what their preference is - it'll be easier to get help from them.
Our suggestions are below, but feel free to ask your coach what their preferences are - it'll be easier to get help from them.

## Gedit

Expand All @@ -14,7 +14,7 @@ Gedit is an open-source, free editor, available for all operating systems.

## Sublime Text 2

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.
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.

[Download it here](http://www.sublimetext.com/2)

Expand Down
19 changes: 11 additions & 8 deletions css/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,9 @@ CSS is a static file, so in order to customize CSS, we need to first configure s

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.

static
manage.py
djangogirls
├─── static
└─── manage.py

Open up the `mysite/settings.py` file, scroll to the bottom of it and add the following lines:

Expand All @@ -55,8 +56,8 @@ This way Django will know where to find your static files.
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?

static
└───css
blog.css
└─── css
blog.css

Time to write some CSS! Open up the `static/css/blog.css` file in your code editor.

Expand All @@ -72,7 +73,7 @@ In your `static/css/blog.css` file you should add following code:

`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!

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`:
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`:

<a href="http://en.wikipedia.org/wiki/Django" class="external_link" id="link_to_wiki_page">

Expand All @@ -86,7 +87,7 @@ We're just loading static files here :). Then, between the `<head>` and `</head>

<link rel="stylesheet" href="{% static 'css/blog.css' %}">

We just told our template where our CSS file is located. Ok, save the file and refresh the site!
We just told our template where our CSS file is located.

Your file should now look like this:

Expand Down Expand Up @@ -114,6 +115,8 @@ Your file should now look like this:
</body>
</html>

OK, save the file and refresh the site!

![Figure 14.2](images/color2.png)

Nice work! Maybe we would also like to give our website a little air and increase the margin on the left side? Let's try this!
Expand Down Expand Up @@ -152,7 +155,7 @@ Go ahead and name some parts of the HTML code. Add a class called `page-header`
<h1><a href="/">Django Girls Blog</a></h1>
</div>

And now add a class `post` to your `div` containing blogposts.
And now add a class `post` to your `div` containing a blog post.

<div class="post">
<p>published: {{ post.published_date }}</p>
Expand Down Expand Up @@ -210,7 +213,7 @@ We will now add declaration blocks to different selectors. Selectors starting wi
color: #000000;
}

Then surround the HTML code which desplayes the posts with declarations of classes. Replace this:
Then surround the HTML code which displays the posts with declarations of classes. Replace this:

{% for post in posts %}
<div class="post">
Expand Down
4 changes: 2 additions & 2 deletions django_admin/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ Let's open the `blog/admin.py` file and replace its content with this:

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)`.

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:
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:

http://127.0.0.1:8000/admin/

Expand All @@ -25,7 +25,7 @@ You should use the username and password you chose when you were creating a data

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 :).

Make sure that at least two or three posts (but not all) have a publish date set. It will be helpful later.
Make sure that at least two or three posts (but not all) have the publish date set. It will be helpful later.

![Django admin](images/edit_post3.png)

Expand Down
29 changes: 15 additions & 14 deletions django_models/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,24 +57,25 @@ A model in Django is a special kind of object - it is saved in the `database` (d

### Creating an application

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`.
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):

(myvenv) ~/djangogirls$ python manage.py startapp blog

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:

mysite
├── __init__.py
├── settings.py
├── urls.py
├── wsgi.py
manage.py
blog
├── __init__.py
├── admin.py
├── models.py
├── tests.py
└── views.py
djangogirls
├── mysite
| __init__.py
| settings.py
| urls.py
| wsgi.py
├── manage.py
└── blog
__init__.py
admin.py
models.py
tests.py
views.py

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:

Expand All @@ -91,7 +92,7 @@ After creating an application we also need to tell Django that it should use it.

### Creating a blog post model

In a file `models.py` we define all objects called `Models` - this is a place in which we will define our blog post.
In the `models.py` file we define all objects called `Models` - this is a place in which we will define our blog post.

Let's open `blog/models.py`, remove everything from it and write code like this:

Expand Down
10 changes: 5 additions & 5 deletions django_orm/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ We have different pieces in place: the `Post` model is defined in `models.py`, w

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.

Ok, so how we will achieve it?
OK, so how we will achieve it?
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It should be "how will we achieve it" here. You mind fixing that too?


We need to open our `blog/views.py`. So far `post_list` *view* looks like this:

Expand All @@ -13,18 +13,18 @@ We need to open our `blog/views.py`. So far `post_list` *view* looks like this:
def post_list(request):
return render(request, 'blog/post_list.html', {})

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:
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:

from django.shortcuts import render
from .models import Post

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`).

But what's next? To take actual blog posts from `Post` model we need something called a `Queryset`.
But what's next? To take actual blog posts from `Post` model we need something called `Queryset`.

## Queryset

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:
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:

Post.objects.all()

Expand Down Expand Up @@ -52,7 +52,7 @@ Now we put this piece of code inside the `post_list` file, by adding it to the f
return render(request, 'blog/post_list.html', {})

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.
The last missing part is to pass the `posts` queryset to the template (we will cover how to display it in a next chapter).
The last missing part is passing the `posts` queryset to the template (we will cover how to display it in a next chapter).

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 `''`.

Expand Down
10 changes: 5 additions & 5 deletions django_start_project/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ The first step towards creating it is starting a new Django project. Basically,

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.

In console you should run (remember that you don't type `(myvenv) ~/djangogirls$`, ok?):
In console you should run (remember that you don't type `(myvenv) ~/djangogirls$`, OK?):

> 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.
> 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.

Run on Windows:

Expand All @@ -27,8 +27,8 @@ or on Linux or Mac OS:

`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:

manage.py
djangogirls
├───manage.py
└───mysite
settings.py
urls.py
Expand All @@ -48,7 +48,7 @@ Let's ignore the other files for now - we won't change them. The only thing to r

Let's make some changes in `mysite/settings.py`. Open the file using the code editor you installed earlier.

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` )
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` )

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:

Expand Down
6 changes: 3 additions & 3 deletions django_templates/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ __Django template tags__ allow us to transfer Python-like things into HTML, so y

## Display post list template

In the previous chapter we gave our template a list of posts in a `posts` variable. Now we will display it in HTML.
In the previous chapter we gave our template a list of posts in the `posts` variable. Now we will display it in HTML.

To print a variable in Django template, we use double curly brackets with the variable's name inside, like this:

Expand All @@ -24,7 +24,7 @@ As you can see, all we've got is this:

[<Post: My second post>, <Post: My first post>]

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:
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:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"[...]Django understands it[...]" (missing final s)


{% for post in posts %}
{{ post }}
Expand All @@ -34,7 +34,7 @@ Try this in your template.

![Figure 13.2](images/step2.png)

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:
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:

<div>
<h1><a href="/">Django Girls Blog</a></h1>
Expand Down
4 changes: 2 additions & 2 deletions django_urls/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,11 @@ As you can see, Django already put something here for us.

Lines that start with `#` are comments - it means that those lines won't be executed by Python. Pretty handy, right?

The admin url, which you visited in previous chapter is already here:
The admin URL, which you visited in previous chapter is already here:

url(r'^admin/', include(admin.site.urls)),

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.
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.

## Regex

Expand Down
4 changes: 2 additions & 2 deletions how_internet_works/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# How the Internet works

*This chapter is inspired by a talk "How the Internet works" by Jessica McKellar (http://web.mit.edu/jesstess/www/).*
> This chapter is inspired by a talk "How the Internet works" by Jessica McKellar (http://web.mit.edu/jesstess/www/).

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'?

Expand All @@ -13,7 +13,7 @@ follow its instructions and present all these files that your website is made of
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
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.

Ok, but you want to know how the Internet looks like, right?
OK, but you want to know how the Internet looks like, right?

We drew you a picture! It looks like this:

Expand Down
Loading