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: deploy/README.md
+2Lines changed: 2 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -126,6 +126,8 @@ Create `.gitignore` file with the following content:
126
126
127
127
and save it. The dot on the beginning of the file name is important! As you can see, we're now telling Heroku to ignore `local_settings.py` and don't download it, so it's only available on your computer (locally).
128
128
129
+
__NOTE:__ Remember to replace `myvenv` with the name you gave your `virtualenv`!
130
+
129
131
Next, we’ll create a new git repository and save our changes. Go to your console and run these commands:
Copy file name to clipboardExpand all lines: django_admin/README.md
+1-1Lines changed: 1 addition & 1 deletion
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. 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:
Copy file name to clipboardExpand all lines: django_installation/README.md
+6-2Lines changed: 6 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -35,10 +35,12 @@ where `C:\Python34\python` is the directory in which you previously installed Py
35
35
36
36
### Linux and OS X
37
37
38
-
Creating a `virtualenv` on both Linux and OS X is as simple as running:
38
+
Creating a `virtualenv` on both Linux and OS X is as simple as running `python3 -m venv myvenv`.
39
+
It will look like this:
39
40
40
41
~/djangogirls$ python3 -m venv myvenv
41
42
43
+
and just like the Windows instructions above, `myvenv` is the name of your `virtualenv`. You can use any other name, but stick to lowercase and use no spaces. It is also good idea to keep the name short - you'll be referencing it a lot!
42
44
43
45
> __NOTE:__ Initiating the virtual environment on Ubuntu 14.04 like this currently gives the following error:
44
46
@@ -52,7 +54,7 @@ Creating a `virtualenv` on both Linux and OS X is as simple as running:
52
54
53
55
## Working with virtualenv
54
56
55
-
The command above will create a directory called `myvenv` that contains our virtual environment (basically bunch of directory and files). All we want to do now is starting it by running:
57
+
The command above will create a directory called `myvenv`(or whichever name you chose) that contains our virtual environment (basically bunch of directory and files). All we want to do now is starting it by running:
Copy file name to clipboardExpand all lines: django_orm/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
@@ -24,7 +24,7 @@ But what's next? To take actual blog posts from `Post` model we need something c
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:
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:
28
28
29
29
Post.objects.all()
30
30
@@ -34,15 +34,15 @@ And we have our first queryset! Now we can take each element out of it and displ
34
34
35
35
But before we pass this queryset to the template and display blog posts we will do some magic and select only posts that are published (they have a `published_date` set).
36
36
37
-
This is where we introduce a `filter`. We will use it instead of `all` in a previous line of code. In parentheses we will state what condition(s) needs to be met by a blog post to end up in our queryset. In our situation it is `published_date` that is not empty. The way to write it in Django is: `published_date__isnull=False` (`null` in programming means *empty*).
37
+
This is where we introduce a `filter`. We will use it instead of `all` in `Post.objects.all()`. In parentheses we will state what condition(s) needs to be met by a blog post to end up in our queryset. In our situation it is `published_date` that is not empty. The way to write it in Django is: `published_date__isnull=False` (`null` in programming means *empty*). Now our piece of code looks like:
38
38
39
39
Post.objects.filter(published_date__isnull=False)
40
40
41
41
Finally, it would be good to have our posts ordered by publish date, right? We can do that with `order_by`. In parentheses we will type (in quotation marks `''`) the name of a field (`published_date`) to order by. Our final queryset looks like this:
Copy file name to clipboardExpand all lines: django_start_project/README.md
+7-5Lines changed: 7 additions & 5 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -17,13 +17,13 @@ In console you should run (remember that you don't type `(myvenv) ~/djangogirls$
17
17
18
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.
`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
@@ -46,7 +46,7 @@ Let's ignore the other files for now - we won't change them. The only thing to r
46
46
47
47
## Changing settings
48
48
49
-
Let's make some changes in `mysite/settings.py`.
49
+
Let's make some changes in `mysite/settings.py`. Open the file using the code editor you installed earlier.
50
50
51
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
@@ -55,6 +55,8 @@ You should find lines that contain `USE_TZ` and `TIME_ZONE` and modify them to l
55
55
USE_TZ = False
56
56
TIME_ZONE = 'Europe/Berlin'
57
57
58
+
(But with the correct country and city for your timezone.)
59
+
58
60
## Setup a database
59
61
60
62
There's a lot of different database software that can store data for your site. We'll use the default one, `sqlite3`.
Don't be surprised with the weird names. Go to the link: http://hubpages.com/hub/50-Doll-Names to look for more cute doll names. :P Just Kidding (You should do this if and only if you have a lot of time).
217
+
Don't be surprised with the weird names. Go to the link: http://hubpages.com/hub/50-Doll-Names to look for more cute doll names. :P Just Kidding (You should do this if and only if you have a lot of time).
218
218
219
-
Above, you just created a variable named django_dolls with three key-value pairs. The key Dottie points to the value 15, Lottie points to the value 305, EmmyLou points to the value 17.
219
+
Above, you just created a variable named django_dolls with three key-value pairs. The key Dottie points to the value 15, Lottie points to the value 305, EmmyLou points to the value 17.
220
220
221
221
When to use a dictionary or a list? Well, a good point to ponder on. Just have a soltuion in mind before looking at the answer in the next line.
222
222
@@ -232,7 +232,7 @@ Like the lists, using len() method on the dictionaries, returns the number of ke
232
232
>>> len(django_dolls)
233
233
4
234
234
235
-
I hope it makes sense uptil now. :) Ready for some more fun with Dictionaries? Hop on the next line for some amazing things.
235
+
I hope it makes sense uptil now. :) Ready for some more fun with Dictionaries? Hop on the next line for some amazing things.
236
236
237
237
You can use del() command to delete an item in the dictionary which has particular. Say, if you want to delete the entry corresponding to the key Dottie, just type in the following command:
238
238
@@ -248,7 +248,7 @@ Apart from this, you can also change a value associated with an already created
248
248
>>> django_dolls
249
249
{'Jilly': 100, 'EmmyLou': 17, 'Lottie': 305}
250
250
251
-
As you can see, the value of the key 'Jilly' has been altered from 67 to 100. :) Exciting? Hurrah! You just learnt another amazing thing.
251
+
As you can see, the value of the key 'Jilly' has been altered from 67 to 100. :) Exciting? Hurrah! You just learnt another amazing thing.
252
252
253
253
### Summary
254
254
@@ -520,6 +520,10 @@ You can also use `for` on numbers using the `range` method:
520
520
521
521
Note that the second of these two numbers is not included in the list that is output by Python (meaning `range(1, 6)` counts from 1 to 5, but does not include the number 6).
522
522
523
+
## Exiting Python
524
+
525
+
You can exit Python and return to the command line using `exit()`.
526
+
523
527
## Summary
524
528
525
529
That's it. __You totally rock!__ This really wasn't so easy, so you should feel proud of yourself. We're definitely proud of you for making it to here!
0 commit comments