From 8cfd0be42f6225ec3b4eb89892406e246e201f74 Mon Sep 17 00:00:00 2001 From: Stephen Steneker Date: Fri, 10 Jul 2015 18:33:46 +1000 Subject: [PATCH] Cleanup some wording and example output based on running through first part of tutorial with Python 3.4.3 and Django 1.8 --- en/code_editor/instructions.md | 4 ++-- en/django/README.md | 4 ++-- en/django_models/README.md | 23 +++++++++++---------- en/django_start_project/README.md | 22 +++++++++++++++----- en/intro_to_command_line/README.md | 2 +- en/python_introduction/README.md | 32 +++++++++++++++--------------- 6 files changed, 50 insertions(+), 37 deletions(-) diff --git a/en/code_editor/instructions.md b/en/code_editor/instructions.md index e6265894115..d399b73ae5c 100644 --- a/en/code_editor/instructions.md +++ b/en/code_editor/instructions.md @@ -26,9 +26,9 @@ Atom is an extremely new code editor created by [GitHub](http://github.com/). It You might be wondering why we are installing this special code editor software, rather than using something like Word or Notepad. -The first is that code needs to be **plain text**, and the problem with programs like Word and Textedit is that they don't actually produce plain text, they produce rich text (with fonts and formatting), using custom formats like rtf. +The first is that code needs to be **plain text**, and the problem with programs like Word and Textedit is that they don't actually produce plain text, they produce rich text (with fonts and formatting), using custom formats like [RTF (Rich Text Format)](https://en.wikipedia.org/wiki/Rich_Text_Format). -The second reason is that code editors are specialised in editing code, so they can provide helpful features, like highlighting code with colour according to its meaning, or automatically closing quotes for you. +The second reason is that code editors are specialised for editing code, so they can provide helpful features like highlighting code with colour according to its meaning, or automatically closing quotes for you. We'll see all this in action later. Soon, you'll come to think of your trusty old code editor as one of your favourite tools :) diff --git a/en/django/README.md b/en/django/README.md index 55080553f68..c5d909fe8b6 100644 --- a/en/django/README.md +++ b/en/django/README.md @@ -1,8 +1,8 @@ # What is Django? -Django (_/ˈdʒæŋɡoʊ/ jang-goh_) is a free and open source web application framework, written in Python. It's a web framework - a set of components that helps you to develop websites faster and easier. +Django (_/ˈdʒæŋɡoʊ/ jang-goh_) is a free and open source web application framework, written in Python. A web framework is a set of components that helps you to develop websites faster and easier. -You see, when you're building a website, you always need a similar set of components: a way to handle user authentication (signing up, signing in, signing out), a management panel for your website, forms, a way to upload files, etc. +When you're building a website, you always need a similar set of components: a way to handle user authentication (signing up, signing in, signing out), a management panel for your website, forms, a way to upload files, etc. 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-made components you can use. diff --git a/en/django_models/README.md b/en/django_models/README.md index fba26825d62..3f883c04e22 100644 --- a/en/django_models/README.md +++ b/en/django_models/README.md @@ -8,9 +8,9 @@ There is a concept in programming called `Object-oriented programming`. The idea So what is an object? It is a collection of properties and actions. It sounds weird, but we will give you an example. -If we want to model a cat we will create an object `Cat` that has some properties, i.e. `color`, `age`, `mood` (i.e. good, bad, sleepy ;)), `owner` (that is a `Person` object or maybe, in case of a stray cat, this property is empty). +If we want to model a cat we will create an object `Cat` that has some properties such as: `color`, `age`, `mood` (i.e. good, bad, sleepy ;)), and `owner` (that is a `Person` object or maybe, in case of a stray cat, this property is empty). -And then the `Cat` has some actions: `purr`, `scratch` or `feed` (in which we will give the cat some `CatFood`, which could be a separate object with properties, i.e. `taste`). +Then the `Cat` has some actions: `purr`, `scratch`, or `feed` (in which we will give the cat some `CatFood`, which could be a separate object with properties, i.e. `taste`). Cat -------- @@ -45,7 +45,7 @@ Well, for sure our blog post needs some text with its content and a title, right What kind of things could be done with a blog post? It would be nice to have some `method` that publishes the post, right? -So we will need `publish` method. +So we will need a `publish` method. Since we already know what we want to achieve, we can start modeling it in Django! @@ -131,19 +131,19 @@ All lines starting with `from` or `import` are lines that add some bits from oth `class Post(models.Model):` - this line defines our model (it is an `object`). - `class` is a special keyword that indicates that we are defining an object. -- `Post` is the name of our model, we can give it a different name (but we must avoid special characters and whitespaces). Always start a class name with an uppercase letter. +- `Post` is the name of our model. We can give it a different name (but we must avoid special characters and whitespaces). Always start a class name with an uppercase letter. - `models.Model` means that the Post is a Django Model, so Django knows that it should be saved in the database. -Now we define properties we were talking about: `title`, `text`, `created_date`, `published_date` and `author`. To do that we need to define a type of field (is it text? A number? A date? A relation to another object, i.e. a User?). +Now we define the properties we were talking about: `title`, `text`, `created_date`, `published_date` and `author`. To do that we need to define a type of each field (Is it text? A number? A date? A relation to another object, i.e. a User?). - `models.CharField` - this is how you define text with a limited number of characters. -- `models.TextField` - this is for long texts without a limit. It will be ideal for a blog post content, right? +- `models.TextField` - this is for long text without a limit. Sounds ideal for blog post content, right? - `models.DateTimeField` - this is a date and time. - `models.ForeignKey` - this is a link to another model. -We will not explain every bit of code here, since it would take too much time. You should take a look at Django's documentation, if you want to know more about Model fields and how to define things other than those described above (https://docs.djangoproject.com/en/1.8/ref/models/fields/#field-types). +We will not explain every bit of code here, since it would take too much time. You should take a look at Django's documentation if you want to know more about Model fields and how to define things other than those described above (https://docs.djangoproject.com/en/1.8/ref/models/fields/#field-types). -What about `def publish(self):`? It is exactly our `publish` method we were talking about before. `def` means that this is a function/method. `publish` is the name of the method. You can change it, if you want. The rule is that we use lowercase and underscores instead of whitespaces (i.e. if you want to have a method that calculates average price you could call it `calculate_average_price`). +What about `def publish(self):`? It is exactly our `publish` method we were talking about before. `def` means that this is a function/method and `publish` is the name of the method. You can change the name of the method, if you want. The naming rule is that we use lowercase and underscores instead of whitespaces (i.e. if you want to have a method that calculates average price you could call it `calculate_average_price`). Methods very often `return` something. There is an example of that in the `__str__` method. In this scenario, when we call `__str__()` we will get a text (**string**) with a Post title. @@ -151,19 +151,20 @@ If something is still not clear about models, feel free to ask your coach! We kn ### Create tables for models in your database -The last step here is to add our new model to our database. First we have to make Django know that we have some changes in our model (we have just created it), type `python manage.py makemigrations blog`. It will look like this: +The last step here is to add our new model to our database. First we have to make Django know that we have some changes in our model (we have just created it!). Type `python manage.py makemigrations blog`. It will look like this: (myvenv) ~/djangogirls$ python manage.py makemigrations blog Migrations for 'blog': 0001_initial.py: - Create model Post -Django prepared for us a migration file that we have to apply now to our database, type `python manage.py migrate blog`, the output should be: +Django prepared for us a migration file that we have to apply now to our database. Type `python manage.py migrate blog` and the output should be: (myvenv) ~/djangogirls$ python manage.py migrate blog Operations to perform: Apply all migrations: blog Running migrations: + Rendering model states... DONE Applying blog.0001_initial... OK -Hurray! Our Post model is now in our database, it would be nice to see it, right? Jump to the next chapter to see what your Post looks like! +Hurray! Our Post model is now in our database! It would be nice to see it, right? Jump to the next chapter to see what your Post looks like! \ No newline at end of file diff --git a/en/django_start_project/README.md b/en/django_start_project/README.md index f47d882d8ea..0acfd8584bc 100644 --- a/en/django_start_project/README.md +++ b/en/django_start_project/README.md @@ -9,11 +9,11 @@ is copyrighted by Markus Zapke-Gründemann et al. We're going to create a simple blog! -The first step towards creating it is to start a new Django project. Basically, this means that we'll run some scripts provided by Django that will create the skeleton of a Django project for us: a bunch of directories and files that we will later use. +The first step is to start a new Django project. Basically, this means that we'll run some scripts provided by Django that will create the skeleton of a Django project for us: a bunch of directories and files that we will later use. 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. -> 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. You can do that by typing the following command: `myvenv\Scripts\activate` on Windows or +> 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. You can do that by typing the following command: `myvenv\Scripts\activate` on Windows or `myvenv/bin/activate` on Mac OS / Linux. In your MacOS or Linux console you should run the following command; **don't forget to add the period (or dot) `.` at the end**: @@ -26,7 +26,7 @@ On Windows; **don't forget to add the period (or dot) `.` at the end**: > The period `.` is crucial because it tells the script to install Django in your current directory (for which the period `.` is a short-hand reference) -> **Note** When typing the commands above, remember that you only type the part which starts `django-admin` or `django-admin.py`. +> **Note** When typing the commands above, remember that you only type the part which starts `django-admin` or `django-admin.py`. The`(myvenv) ~/djangogirls$` and `(myvenv) C:\Users\Name\djangogirls>` parts shown here are just examples of the prompt that will be inviting your input on your command line. @@ -69,7 +69,7 @@ We'll also need to add a path for static files (we'll find out all about static ```python STATIC_URL = '/static/' -STATIC_ROOT = os.path.join(BASE_DIR, 'static') +STATIC_ROOT = os.path.join(BASE_DIR, 'static') ``` @@ -92,11 +92,23 @@ To create a database for our blog, let's run the following in the console: `pyth (myvenv) ~/djangogirls$ python manage.py migrate Operations to perform: - Apply all migrations: admin, contenttypes, auth, sessions + Synchronize unmigrated apps: messages, staticfiles + Apply all migrations: contenttypes, sessions, admin, auth + Synchronizing apps without migrations: + Creating tables... + Running deferred SQL... + Installing custom SQL... Running migrations: + Rendering model states... DONE Applying contenttypes.0001_initial... OK Applying auth.0001_initial... OK Applying admin.0001_initial... OK + Applying contenttypes.0002_remove_content_type_name... OK + Applying auth.0002_alter_permission_name_max_length... OK + Applying auth.0003_alter_user_email_max_length... OK + Applying auth.0004_alter_user_username_opts... OK + Applying auth.0005_alter_user_last_login_null... OK + Applying auth.0006_require_contenttypes_0002... OK Applying sessions.0001_initial... OK And we're done! Time to start the web server and see if our website is working! diff --git a/en/intro_to_command_line/README.md b/en/intro_to_command_line/README.md index 0552f573aeb..a612035c936 100644 --- a/en/intro_to_command_line/README.md +++ b/en/intro_to_command_line/README.md @@ -144,7 +144,7 @@ Windows: > mkdir djangogirls -This little command will create a folder with the name `djangogirls` on your desktop. You can check if it's there just by looking on your Desktop or by running a `ls`/`dir` command! Try it :) +This little command will create a folder with the name `djangogirls` on your desktop. You can check if it's there just by looking on your Desktop or by running a `ls` or `dir` command! Try it :) > PRO tip: If you don't want to type the same commands over and over, try pressing the `up arrow` and `down arrow` on your keyboard to cycle through recently used commands. diff --git a/en/python_introduction/README.md b/en/python_introduction/README.md index e89377d2cef..b2d74f80b47 100644 --- a/en/python_introduction/README.md +++ b/en/python_introduction/README.md @@ -13,8 +13,8 @@ Once you're ready, follow the instructions below. We want to open up a Python console, so type in `python` on Windows or `python3` on Mac OS/Linux and hit `enter`. $ python3 - Python 3.4.2 (...) - Type "copyright", "credits" or "license" for more information. + Python 3.4.3 (...) + Type "help", "copyright", "credits" or "license" for more information. >>> ## Your first Python command! @@ -23,7 +23,7 @@ After running the Python command, the prompt changed to `>>>`. For us this means If you want to exit the Python console at any point, just type `exit()` or use the shortcut `Ctrl + Z` for Windows and `Ctrl + D` for Mac/Linux. Then you won't see `>>>` any longer. -But now, we don't want to exit the Python console. We want to learn more about it. Let's start with something really simple. For example, try typing some math, like `2 + 3` and hit `enter`. +For now, we don't want to exit the Python console. We want to learn more about it. Let's start with something really simple. For example, try typing some math, like `2 + 3` and hit `enter`. >>> 2 + 3 5 @@ -276,16 +276,16 @@ What happens if we ask Python the value of a key that doesn't exist? Can you gue Look, another error! This one is a **KeyError**. Python is helpful and tells you that the key `'age'` doesn't exist in this dictionary. -When to use a dictionary or a list? Well, that's a good point to ponder on. Just have a solution in mind before looking at the answer in the next line. +When should you use a dictionary or a list? Well, that's a good point to ponder. Just have a solution in mind before looking at the answer in the next line. - Do you just need an ordered sequence of items? Go for a list. - Do you need to associate values with keys, so you can look them up efficiently (by key) later on? Use a dictionary. -Dictionaries, like lists, are *mutable*, meaning that they can be changed after they are created. You can add new key/value pairs to the dictionary after it is created, like: +Dictionaries, like lists, are *mutable*, meaning that they can be changed after they are created. You can add new key/value pairs to a dictionary after it is created, like: >>> participant['favorite_language'] = 'Python' -Like lists, using `len()` method on the dictionaries, returns the number of key-value pairs in the dictionary. Go ahead and type in the command: +Like lists, using the `len()` method on the dictionaries returns the number of key-value pairs in the dictionary. Go ahead and type in the command: >>> len(participant) 4 @@ -409,7 +409,7 @@ Congrats! Booleans are one of the coolest features in programming, and you just # Save it! -So far we've been writing all our python code in the interpreter, which limits us to one line of code at a time. Normal programs are saved in files and executed by our programming language __interpreter__ or __compiler__. So far we've been running our programs one line at a time in the Python __interpreter__. We're going to need more than one line of code for the next few tasks, so we'll quickly need to: +So far we've been writing all our python code in the interpreter, which limits us to entering one line of code at a time. Normal programs are saved in files and executed by our programming language __interpreter__ or __compiler__. So far we've been running our programs one line at a time in the Python __interpreter__. We're going to need more than one line of code for the next few tasks, so we'll quickly need to: - Exit the Python interpreter - Open up our code editor of choice @@ -429,12 +429,12 @@ Earlier, we picked out a code editor from the [code editor](../code_editor/READM print('Hello, Django girls!') ``` -> **Note** You should notice one of the coolest thing about code editors: colours! In the Python console, everything was the same colour, now you should see that the `print` function is a different colour from the string. This is called "syntax highlighting", and it's a really useful feature when coding. The colour of things will give you hints, such as unclosed strings, or a typo in a keyword name (like the `def` in a function, which we'll see below). This is one of the reasons we use a code editor :) +> **Note** You should notice one of the coolest thing about code editors: colours! In the Python console, everything was the same colour, now you should see that the `print` function is a different colour from the string. This is called "syntax highlighting", and it's a really useful feature when coding. The colour of things will give you hints, such as unclosed strings or a typo in a keyword name (like the `def` in a function, which we'll see below). This is one of the reasons we use a code editor :) -Obviously, you're a pretty seasoned python developer now, so feel free to write some code that you've learned today. +Obviously, you're a pretty seasoned Python developer now, so feel free to write some code that you've learned today. -Now we need to save the file and give it a descriptive name. Let's call the file **python_intro.py** and save it to your desktop. We can name the file anything we want, the important part here is to make sure the file ends in __.py__, this tells our computer that this is a **python executable file** and Python can run it. +Now we need to save the file and give it a descriptive name. Let's call the file **python_intro.py** and save it to your desktop. We can name the file anything we want, but the important part here is to make sure the file ends in __.py__. The __.py__ extension tells our operating system that this is a **python executable file** and Python can run it. With the file saved, it's time to run it! Using the skills you've learned in the command line section, use the terminal to **change directories** to the desktop. @@ -452,12 +452,12 @@ And on windows, it will be like this: If you get stuck, just ask for help. -and then use Python to execute the code in the file like this: +Now use Python to execute the code in the file like this: $ python3 python_intro.py Hello, Django girls! -Alright! You just ran your first python program that was saved to a file. Feel awesome? +Alright! You just ran your first Python program that was saved to a file. Feel awesome? You can now move on to an essential tool in programming: @@ -492,7 +492,7 @@ Save it and give it another run: $ python3 python_intro.py It works! -### What if not? +### What if a condition isn't True? In previous examples, code was executed only when the conditions were True. But Python also has `elif` and `else` statements: @@ -503,7 +503,7 @@ else: print('5 is not greater than 2') ``` -When this is ran it will print out: +When this is run it will print out: $ python3 python_intro.py 5 is indeed greater than 2 @@ -540,9 +540,9 @@ Time for the last part of this chapter! ## Your own functions! -Remember functions like `len()` that you can execute in Python? Well, good news, you will learn how to write your own functions now! +Remember functions like `len()` that you can execute in Python? Well, good news - you will learn how to write your own functions now! -A function is a sequence of instructions that Python should execute. Each function in Python starts with the keyword `def`, is given a name, and it can have some parameters. Let's start with an easy one. Replace the code in **python_intro.py** with the following: +A function is a sequence of instructions that Python should execute. Each function in Python starts with the keyword `def`, is given a name, and can have some parameters. Let's start with an easy one. Replace the code in **python_intro.py** with the following: ```python def hi():