Skip to content

Commit

Permalink
Merge pull request DjangoGirls#1225 from jacebrowning/advance-error-n…
Browse files Browse the repository at this point in the history
…otice

Include a warning icon before blocks that return errors
  • Loading branch information
RachellCalhoun authored Mar 6, 2018
2 parents db70d19 + c635685 commit e7526d6
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 10 deletions.
8 changes: 5 additions & 3 deletions en/extend_your_application/README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
{% set warning_icon = '<span class="glyphicon glyphicon-exclamation-sign" style="color: red;" aria-hidden="true" data-toggle="tooltip" title="An error is expected when you run this code!" ></span>' %}

# Extend your application

We've already completed all the different steps necessary for the creation of our website: we know how to write a model, url, view and template. We also know how to make our website pretty.
Expand Down Expand Up @@ -30,7 +32,7 @@ We will start with adding a link inside `blog/templates/blog/post_list.html` fil

{% raw %}We want to have a link from a post's title in the post list to the post's detail page. Let's change `<h1><a href="">{{ post.title }}</a></h1>` so that it links to the post's detail page:{% endraw %}

{% filename %}blog/templates/blog/post_list.html{% endfilename %}
{% filename %}{{ warning_icon }} blog/templates/blog/post_list.html{% endfilename %}
```html
<h1><a href="{% url 'post_detail' pk=post.pk %}">{{ post.title }}</a></h1>
```
Expand All @@ -53,7 +55,7 @@ We want our first post's detail to be displayed at this **URL**: http://127.0.0.

Let's make a URL in the `blog/urls.py` file to point Django to a *view* named `post_detail`, that will show an entire blog post. Add the line `url(r'^post/(?P<pk>\d+)/$', views.post_detail, name='post_detail'),` to the `blog/urls.py` file. The file should look like this:

{% filename %}blog/urls.py{% endfilename %}
{% filename %}{{ warning_icon }} blog/urls.py{% endfilename %}
```python
from django.conf.urls import url
from . import views
Expand Down Expand Up @@ -85,7 +87,7 @@ This time our *view* is given an extra parameter, `pk`. Our *view* needs to catc

Now, we want to get one and only one blog post. To do this, we can use querysets, like this:

{% filename %}blog/views.py{% endfilename %}
{% filename %}{{ warning_icon }} blog/views.py{% endfilename %}
```python
Post.objects.get(pk=pk)
```
Expand Down
18 changes: 11 additions & 7 deletions en/python_introduction/README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
{% set warning_icon = '<span class="glyphicon glyphicon-exclamation-sign" style="color: red;" aria-hidden="true" data-toggle="tooltip" title="An error is expected when you run this command!" ></span>' %}

# Introduction to Python

> Part of this chapter is based on tutorials by Geek Girls Carrots (https://github.com/ggcarrots/django-carrots).
Expand Down Expand Up @@ -134,15 +136,17 @@ These are the basics of every programming language you learn. Ready for somethin

Let's try something new. Can we get the length of a number the same way we could find out the length of our name? Type in `len(304023)` and hit `enter`:

{% filename %}command-line{% endfilename %}
{% filename %}{{ warning_icon }} command-line{% endfilename %}
```python
>>> len(304023)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: object of type 'int' has no len()
```

We got our first error! It says that objects of type "int" (integers, whole numbers) have no length. So what can we do now? Maybe we can write our number as a string? Strings have a length, right?
We got our first error! The {{ warning_icon }} icon is our way of giving you a heads up that the code you are about to run won't work as expected. Making mistakes (even intentional ones) are an important part of learning!

It says that objects of type "int" (integers, whole numbers) have no length. So what can we do now? Maybe we can write our number as a string? Strings have a length, right?

{% filename %}command-line{% endfilename %}
```python
Expand Down Expand Up @@ -207,7 +211,7 @@ Awesome, right? Of course, variables can be anything – numbers too! Try this:

But what if we used the wrong name? Can you guess what would happen? Let's try!

{% filename %}command-line{% endfilename %}
{% filename %}{{ warning_icon }} command-line{% endfilename %}
```python
>>> city = "Tokyo"
>>> ctiy
Expand Down Expand Up @@ -372,7 +376,7 @@ See, it's similar to a list. But you don't need to remember the index – just t

What happens if we ask Python the value of a key that doesn't exist? Can you guess? Let's try it and see!

{% filename %}command-line{% endfilename %}
{% filename %}{{ warning_icon }} command-line{% endfilename %}
```python
>>> participant['age']
Traceback (most recent call last):
Expand Down Expand Up @@ -498,7 +502,7 @@ You can give Python as many numbers to compare as you want, and it will give you

Have you heard of the expression "comparing apples to oranges"? Let's try the Python equivalent:

{% filename %}command-line{% endfilename %}
{% filename %}{{ warning_icon }} command-line{% endfilename %}
```python
>>> 1 > 'django'
Traceback (most recent call last):
Expand Down Expand Up @@ -663,7 +667,7 @@ if 3 > 2:

If we were to save and run this, we'd see an error like this:

{% filename %}command-line{% endfilename %}
{% filename %}{{ warning_icon }} command-line{% endfilename %}
```
$ python3 python_intro.py
File "python_intro.py", line 2
Expand Down Expand Up @@ -849,7 +853,7 @@ hi()

Remember: The `print` function is indented four spaces within the `if` statement. This is because the function runs when the condition is met. Let's see how it works now:

{% filename %}command-line{% endfilename %}
{% filename %}{{ warning_icon }} command-line{% endfilename %}
```
$ python3 python_intro.py
Traceback (most recent call last):
Expand Down

0 comments on commit e7526d6

Please sign in to comment.