Skip to content

Commit cb3412a

Browse files
committed
Merge pull request DjangoGirls#20 from bmispelon/consistent-abs-paths
Used consistent absolute file paths.
2 parents 1bb00bd + 65d8048 commit cb3412a

12 files changed

Lines changed: 44 additions & 44 deletions

File tree

css/README.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -52,21 +52,21 @@ That's it! Time to see if it works :)
5252

5353
First things first: let's create a CSS file now. Create a new folder called `css` inside your `static` folder. Then create a new file called `blog.css` inside this `css` directory. Ready?
5454

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

5757
We won't be going too deep into customizing and learning about CSS here, because it's pretty easy and you can learn it on your own after this workshop. We really recommend doing this [Codeacademy HTML & CSS course](http://www.codecademy.com/tracks/web) to learn everything you need to know about making your websites more pretty with CSS.
5858

5959
But let's do at least a little. Maybe we could change the color of our header? To understand colors, computer use special codes. They start with `#` and are followed by 6 letters and numbers. You can find color codes for example here: http://www.colorpicker.com/
6060

61-
In your `blog.css` file you should add following code:
61+
In your `mysite/static/css/blog.css` file you should add following code:
6262

6363
h1 a {
6464
color: #FCA205;
6565
}
6666

6767
`a` inside of `h1` is the tag we're applying our styles to, and we're telling it to change color to `#FCA205`. Of course, you can put your own color here!
6868

69-
Then, we need to also tell our HTML template that we added some CSS. Open the `post_list.html` file and add this line at the very beginning of it:
69+
Then, we need to also tell our HTML template that we added some CSS. Open the `mysite/blog/templates/blog/post_list.html` file and add this line at the very beginning of it:
7070

7171
{% load staticfiles %}
7272

@@ -88,13 +88,13 @@ Add this to your CSS, save the file and see how it works!
8888

8989
![Figure 14.3](images/margin2.png)
9090

91-
Maybe we can customize the font in our header? Paste this into your `<head>` in `post_list.html` file:
91+
Maybe we can customize the font in our header? Paste this into your `<head>` in `mysite/blog/templates/blog/post_list.html` file:
9292

9393
<link href="http://fonts.googleapis.com/css?family=Lobster&subset=latin,latin-ext" rel="stylesheet" type="text/css">
9494

9595
This line will import a font called Lobster from Google Fonts.
9696

97-
Now add this line in `blog.css`:
97+
Now add this line in `mysite/static/css/blog.css`:
9898

9999
h1 a {
100100
color: #FCA205;
@@ -121,7 +121,7 @@ And now add a class `post` to your `div` containing blogposts.
121121
<p>{{ post.text }}</p>
122122
</div>
123123

124-
All right. We have only one day, so we need to speed things up a little! We can't explain you every little detail about CSS. For now just copy and paste following code into your `blog.css` file:
124+
All right. We have only one day, so we need to speed things up a little! We can't explain you every little detail about CSS. For now just copy and paste following code into your `mysite/static/css/blog.css` file:
125125

126126
.page-header {
127127
background-color: #ff9400;
@@ -181,7 +181,7 @@ Then also replace this:
181181
</div>
182182
{% endfor %}
183183

184-
in the `<body>` of your `post_list.html` with this:
184+
in the `<body>` of your `mysite/blog/templates/blog/post_list.html` with this:
185185

186186
<div class="content">
187187
<div class="row">

deploy/README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ We need to tell Heroku which Python version we want to use. This is simply done
3636

3737
## mysite/settings.py
3838

39-
Another thing we need to do is modify our website's `settings.py` file. Open `mysite/settings.py` in your editor and add the following lines:
39+
Another thing we need to do is modify our website's `settings.py` file. Open `mysite/mysite/settings.py` in your editor and add the following lines:
4040

4141
import dj_database_url
4242
DATABASES['default'] = dj_database_url.config()
@@ -51,7 +51,7 @@ Then save the file.
5151

5252
## mysite/urls.py
5353

54-
Open `mysite/urls.py` file and add these two line in the beginning of the file:
54+
Open `mysite/mysite/urls.py` file and add these two line in the beginning of the file:
5555

5656
from django.conf.urls.static import static
5757
from django.conf import settings
@@ -69,7 +69,7 @@ The whole thing should look like this:
6969

7070
## mysite/wsgi.py
7171

72-
Open the `mysite/wsgi.py` file and replace this line:
72+
Open the `mysite/mysite/wsgi.py` file and replace this line:
7373

7474
application = get_wsgi_application()
7575

@@ -94,7 +94,7 @@ Then authenticate Heroku account on you computer by running this command:
9494

9595
Heroku uses git repository to manage your project files, so we need to use it to.
9696

97-
Create `.gitignore` file with following content:
97+
Create `mysite/.gitignore` file with following content:
9898

9999
venv
100100
__pycache__

django_admin/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
To add, edit and delete posts we have just modeled, we will use the Django admin.
44

5-
Let's open `blog/admin.py` file and replace its content with this:
5+
Let's open `mysite/blog/admin.py` file and replace its content with this:
66

77
from django.contrib import admin
88
from .models import Post

django_forms/README.md

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ This is exactly what we want to do: we will create a form for our `Post`.
88

99
Like every important part of Django, forms have their own file: `forms.py`.
1010

11-
We need to create a file with this name in the `blog` folder.
11+
We need to create a file with this name in the `mysite/blog` folder.
1212

1313
└── blog
1414
└── forms.py
@@ -39,7 +39,7 @@ So once again we will create: a link to the page, a url, a view and a template.
3939

4040
## Link to page with the form
4141

42-
It's time to open `mysite/template/mysite/base.html`. We will add a link in `div` named `page-header`:
42+
It's time to open `mysite/mysite/templates/mysite/base.html`. We will add a link in `div` named `page-header`:
4343

4444
<a href="{% url 'blog.views.post_new' %}" class="top-menu"><span class="glyphicon glyphicon-plus"></span></a>
4545

@@ -83,7 +83,7 @@ After saving and refreshing the page `http://127.0.0.1:8000` you will obviously
8383

8484
## Url
8585

86-
We open `blog/urls.py` and add a line:
86+
We open `mysite/blog/urls.py` and add a line:
8787

8888
url(r'^post/new/$', views.post_new),
8989

@@ -102,7 +102,7 @@ After refreshing the site, we see an `AttributeError`, since we don't have `post
102102

103103
## post_new view
104104

105-
Time to open the `blog/views.py` file and add the following lines:
105+
Time to open the `mysite/blog/views.py` file and add the following lines:
106106

107107
from .forms import PostForm
108108

@@ -116,7 +116,7 @@ To create a new Post form, we need to call `PostForm()` and pass it to the templ
116116

117117
## Template
118118

119-
We need to create a file `post_edit.html` in the `blog/template/blog` directory. To make a form work we need several things:
119+
We need to create a file `post_edit.html` in the `mysite/blog/template/blog` directory. To make a form work we need several things:
120120

121121
- we need to display the form. We can do that for example with a `{{ form.as_p }}`.
122122
- the line above have to be wrapped with HTML form tag: <`form method="POST">...</form>`
@@ -149,7 +149,7 @@ The answer is: nothing. We need to do a little bit more work in our view.
149149

150150
## Saving the form
151151

152-
Open `blog/views.py` once again. Currently all we have in `post_new` view is:
152+
Open `mysite/blog/views.py` once again. Currently all we have in `post_new` view is:
153153

154154
def post_new(request):
155155
form = PostForm()
@@ -221,7 +221,7 @@ Django is taking care of validating that all fields in our form are correct. Isn
221221

222222
Now we know how to add new form. But what if we want to edit an existing one? It is very similar to the thing we just did. Let's create some important things quickly (if you don't understand something - you should ask your coach or look at the previous chapters, since we covered all the steps already).
223223

224-
Open `blog/post_detail.html` and add this line:
224+
Open `mysite/blog/post_detail.html` and add this line:
225225

226226
<a class="btn btn-default" href="{% url 'post_edit' pk=post.pk %}"><span class="glyphicon glyphicon-pencil"></span></a>
227227

@@ -240,13 +240,13 @@ so that the template will look like:
240240
<p>{{ post.text }}</p>
241241
{% endblock %}
242242

243-
In `blog/urls.py` we add this line:
243+
In `mysite/blog/urls.py` we add this line:
244244

245245
url(r'^post/(?P<pk>[0-9]+)/edit/$', views.post_edit, name='post_edit'),
246246

247-
We will reuse the template `blog/template/blog/post_edit.html`, so last the thing missing is a view.
247+
We will reuse the template `mysite/blog/templates/blog/post_edit.html`, so last the thing missing is a view.
248248

249-
Let's open a `blog/views.py` and add at the very end of the file:
249+
Let's open a `mysite/blog/views.py` and add at the very end of the file:
250250

251251
def post_edit(request, pk):
252252
post = get_object_or_404(Post, pk=pk)

django_models/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ You will notice that a new `blog` folder is created and it contains a number of
7777
├── tests.py
7878
└── views.py
7979

80-
After creating an application we also need to tell Django that it should use it. We do that in the file `mysite/setting.py`. We need to find `INSTALLED_APPS` and add a line `blog` just above `)`. We should also add `mysite` application (which was created for us when we started a new project in last chapter). So the final product should look like this:
80+
After creating an application we also need to tell Django that it should use it. We do that in the file `mysite/mysite/setting.py`. We need to find `INSTALLED_APPS` and add a line `blog` just above `)`. We should also add `mysite` application (which was created for us when we started a new project in last chapter). So the final product should look like this:
8181

8282
INSTALLED_APPS = (
8383
'django.contrib.admin',
@@ -94,7 +94,7 @@ After creating an application we also need to tell Django that it should use it.
9494

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

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

9999
from django.db import models
100100
from django.utils import timezone

django_orm_querysets/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ This is exactly what `views` are supposed to do: connect models and templates. I
66

77
Ok, so how we will achieve it?
88

9-
We need to open our `blog/views.py`. So far `post_list` view looks like this:
9+
We need to open our `mysite/blog/views.py`. So far `post_list` view looks like this:
1010

1111
from django.shortcuts import render
1212

@@ -54,7 +54,7 @@ The last missing part is to pass the `posts` queryset to the template (we will c
5454

5555
In the `render` function we already have parameter with `request` (so everything we receive from the user via internet) and a template file `'blog/post_list.html'`. The last parameter, which looks like this now: `{}` is a place in which we can pass some things to template. We need to give them names (we will stick with `'posts'` right now :)). It should look like this: `{'posts': posts}`.
5656

57-
So finally our `views.py` file should look like this:
57+
So finally our `mysite/blog/views.py` file should look like this:
5858

5959
from django.shortcuts import render
6060
from .models import Post

django_templates/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ To print a variable in Django template, we use double curly brackets with the va
1616

1717
{{ posts }}
1818

19-
Try this in your `post_list.html` template, save the file and refresh the page to see the results:
19+
Try this in your `mysite/blog/templates/blog/post_list.html` template, save the file and refresh the page to see the results:
2020

2121
![Figure 13.1](images/step1.png)
2222

django_urls/README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ Every page on the internet needs its own URL. This way your application knows wh
1212

1313
## How URLs work in Django?
1414

15-
Let's open up the `mysite/urls.py` file and see how it looks:
15+
Let's open up the `mysite/mysite/urls.py` file and see how it looks:
1616

1717
from django.conf.urls import patterns, include, url
1818

@@ -45,10 +45,10 @@ Do you wonder how Django matches URLs to views? Well, this part is tricky. Djang
4545

4646
Time to create our first urls! We want http://127.0.0.1:8000/ to be a homepage of our blog and display a list posts.
4747

48-
We also want to keep `mysite/urls.py` file clean, so we will import urls from our `blog` application to main `mysite/urls.py` file.
48+
We also want to keep `mysite/mysite/urls.py` file clean, so we will import urls from our `blog` application to main `mysite/mysite/urls.py` file.
4949
Go ahead, delete comment lines and add a line that will import `blog.urls` into main url (`''`).
5050

51-
Your `mysite/urls.py` file should now look like this:
51+
Your `mysite/mysite/urls.py` file should now look like this:
5252

5353
from django.conf.urls import patterns, include, url
5454

extend_your_application/README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ We already have a `Post` model, so we don't need to add anything to `models.py`.
1010

1111
## Create a link in the template
1212

13-
We will start with adding a link inside `post_list.html` (in `blog/template/blog` directory) file. So far it should look like:
13+
We will start with adding a link inside `mysite/blog/templates/blog/post_list.html` file. So far it should look like:
1414

1515
<html>
1616
<head>
@@ -97,7 +97,7 @@ The good news is that you actually can create your own `Page not found` page and
9797

9898
Ok, time to add a view to our `views.py` file!
9999

100-
We should open `blog/views.py` and add the following code:
100+
We should open `mysite/blog/views.py` and add the following code:
101101

102102
from django.shortcuts import render, get_object_or_404
103103

@@ -119,7 +119,7 @@ It worked! But what happens when you click a link in blog post title?
119119

120120
Oh no! Error once again. But we already know how to deal with it, right? We need to add a template!
121121

122-
We will create a file in `blog/template/blog` called `post_detail.html`.
122+
We will create a file in `mysite/blog/templates/blog` called `post_detail.html`.
123123

124124
It will look like this:
125125

homework_add_more_to_your_website/README.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,19 +12,19 @@ Let's add a link in `mysite/templates/mysite/base.html` near the button for addi
1212

1313
<a href="{% url 'post_draft_list' %}" class="top-menu"><span class="glyphicon glyphicon-edit"></span></a>
1414

15-
Next: urls! In `blog/urls.py` we add:
15+
Next: urls! In `mysite/blog/urls.py` we add:
1616

1717
url(r'^drafts/$', views.post_draft_list, name='post_draft_list'),
1818

19-
Time to create a view in `blog/views.py`:
19+
Time to create a view in `mysite/blog/views.py`:
2020

2121
def post_draft_list(request):
2222
posts = Post.objects.filter(published_date__isnull=True).order_by('created_date')
2323
return render(request, 'blog/post_draft_list.html', {'posts': posts})
2424

2525
This line `Post.objects.filter(published_date__isnull=True).order_by('created_date')` makes sure we take only unpublished posts (`published_date__isnull=True`) and order them by `created_date` (`order_by('created_date')`).
2626

27-
Ok, the last bit is of course a template! Create a file `blog/templates/blog/post_draft_list.html` and add the following:
27+
Ok, the last bit is of course a template! Create a file `mysite/blog/templates/blog/post_draft_list.html` and add the following:
2828

2929
{% extends 'mysite/base.html' %}
3030

@@ -48,7 +48,7 @@ Yay! First task is done!
4848

4949
It would be nice to have a button on post detail page that will immediatelly publish the post, right?
5050

51-
Let's open `blog/template/blog/post_detail.html` and change these lines:
51+
Let's open `mysite/blog/template/blog/post_detail.html` and change these lines:
5252

5353
{% if post.published_date %}
5454
{{ post.published_date }}
@@ -64,11 +64,11 @@ into these ones:
6464

6565
As you noticed, we added `{% else %}` line here. That means, that if the condition from `{% if post.published_date %}` is not fulfilled (so if there is no `published_date`), then we want to do the line `<a class="btn btn-default" href="{% url 'post_publish' pk=post.pk %}">Publish</a>`. Note that we are passing a `pk` variable in the `{% url %}`.
6666

67-
Time to create a url (in `blog/urls.py`):
67+
Time to create a url (in `mysite/blog/urls.py`):
6868

6969
url(r'^post/(?P<pk>[0-9]+)/publish/$', views.post_publish, name='post_publish'),
7070

71-
and finally, a view (as always, in `blog/views.py`):
71+
and finally, a view (as always, in `mysite/blog/views.py`):
7272

7373
def post_publish(request, pk):
7474
post = get_object_or_404(Post, pk=pk)
@@ -91,17 +91,17 @@ Congratulations! You are almost there. The last step is adding a delete button!
9191

9292
## Delete post
9393

94-
Let's open `blog/templates/blog/post_detail.html` once again and add this line:
94+
Let's open `mysite/blog/templates/blog/post_detail.html` once again and add this line:
9595

9696
<a class="btn btn-default" href="{% url 'post_remove' pk=post.pk %}"><span class="glyphicon glyphicon-remove"></span></a>
9797

9898
just under a line with edit button.
9999

100-
Now we need an url (`blog/urls.py`):
100+
Now we need an url (`mysite/blog/urls.py`):
101101

102102
url(r'^post/(?P<pk>[0-9]+)/remove/$', views.post_remove, name='post_remove'),
103103

104-
Now, time for a view! Open `blog/views.py` and add this code:
104+
Now, time for a view! Open `mysite/blog/views.py` and add this code:
105105

106106
def post_remove(request, pk):
107107
post = get_object_or_404(Post, pk=pk)

0 commit comments

Comments
 (0)