From 65d80482e40509a20a7f5af48c5bf2bdf5a9baed Mon Sep 17 00:00:00 2001 From: Baptiste Mispelon Date: Sun, 6 Jul 2014 12:11:51 +0200 Subject: [PATCH] Used consistent absolute file paths. When giving the name of a file for editing, the "absolute" path is always used ("absolute" relative to the root of the project) --- css/README.md | 14 +++++++------- deploy/README.md | 8 ++++---- django_admin/README.md | 2 +- django_forms/README.md | 20 ++++++++++---------- django_models/README.md | 4 ++-- django_orm_querysets/README.md | 4 ++-- django_templates/README.md | 2 +- django_urls/README.md | 6 +++--- extend_your_application/README.md | 6 +++--- homework_add_more_to_your_website/README.md | 18 +++++++++--------- starting_django_project/README.md | 2 +- template_extending/README.md | 2 +- 12 files changed, 44 insertions(+), 44 deletions(-) diff --git a/css/README.md b/css/README.md index 800d7989f99..4a04d4afb38 100644 --- a/css/README.md +++ b/css/README.md @@ -52,13 +52,13 @@ That's it! Time to see if it works :) 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? -Time to write some CSS! Open up the `blog.css` file in your code editor. +Time to write some CSS! Open up the `mysite/static/css/blog.css` file in your code editor. 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. 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/ -In your `blog.css` file you should add following code: +In your `mysite/static/css/blog.css` file you should add following code: h1 a { color: #FCA205; @@ -66,7 +66,7 @@ In your `blog.css` file you should add following code: `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! -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: +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: {% load staticfiles %} @@ -88,13 +88,13 @@ Add this to your CSS, save the file and see how it works! ![Figure 14.3](images/margin2.png) -Maybe we can customize the font in our header? Paste this into your `` in `post_list.html` file: +Maybe we can customize the font in our header? Paste this into your `` in `mysite/blog/templates/blog/post_list.html` file: This line will import a font called Lobster from Google Fonts. -Now add this line in `blog.css`: +Now add this line in `mysite/static/css/blog.css`: h1 a { color: #FCA205; @@ -121,7 +121,7 @@ And now add a class `post` to your `div` containing blogposts.

{{ post.text }}

-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: +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: .page-header { background-color: #ff9400; @@ -181,7 +181,7 @@ Then also replace this: {% endfor %} -in the `` of your `post_list.html` with this: +in the `` of your `mysite/blog/templates/blog/post_list.html` with this:
diff --git a/deploy/README.md b/deploy/README.md index cbc99020bb7..62fdf78df96 100644 --- a/deploy/README.md +++ b/deploy/README.md @@ -30,7 +30,7 @@ Then save it. Done! ## mysite/settings.py -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: +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: import dj_database_url DATABASES['default'] = dj_database_url.config() @@ -45,7 +45,7 @@ Then save the file. ## mysite/urls.py -Open `mysite/urls.py` file and add these two line in the beginning of the file: +Open `mysite/mysite/urls.py` file and add these two line in the beginning of the file: from django.conf.urls.static import static from django.conf import settings @@ -63,7 +63,7 @@ The whole thing should look like this: ## mysite/wsgi.py -Open the `mysite/wsgi.py` file and replace this line: +Open the `mysite/mysite/wsgi.py` file and replace this line: application = get_wsgi_application() @@ -88,7 +88,7 @@ Then authenticate Heroku account on you computer by running this command: Heroku uses git repository to manage your project files, so we need to use it to. -Create `.gitignore` file with following content: +Create `mysite/.gitignore` file with following content: venv __pycache__ diff --git a/django_admin/README.md b/django_admin/README.md index 0869bccf740..4e856b43084 100644 --- a/django_admin/README.md +++ b/django_admin/README.md @@ -2,7 +2,7 @@ To add, edit and delete posts we have just modeled, we will use the Django admin. -Let's open `blog/admin.py` file and replace its content with this: +Let's open `mysite/blog/admin.py` file and replace its content with this: from django.contrib import admin from .models import Post diff --git a/django_forms/README.md b/django_forms/README.md index 4c98816b671..ecb57dcbad5 100644 --- a/django_forms/README.md +++ b/django_forms/README.md @@ -8,7 +8,7 @@ This is exactly what we want to do: we will create a form for our `Post`. Like every important part of Django, forms have their own file: `forms.py`. -We need to create a file with this name in the `blog` folder. +We need to create a file with this name in the `mysite/blog` folder. └── blog └── forms.py @@ -39,7 +39,7 @@ So once again we will create: a link to the page, a url, a view and a template. ## Link to page with the form -It's time to open `mysite/template/mysite/base.html`. We will add a link in `div` named `page-header`: +It's time to open `mysite/mysite/templates/mysite/base.html`. We will add a link in `div` named `page-header`: @@ -83,7 +83,7 @@ After saving and refreshing the page `http://127.0.0.1:8000` you will obviously ## Url -We open `blog/urls.py` and add a line: +We open `mysite/blog/urls.py` and add a line: url(r'^post/new/$', views.post_new), @@ -102,7 +102,7 @@ After refreshing the site, we see an `AttributeError`, since we don't have `post ## post_new view -Time to open the `blog/views.py` file and add the following lines: +Time to open the `mysite/blog/views.py` file and add the following lines: from .forms import PostForm @@ -116,7 +116,7 @@ To create a new Post form, we need to call `PostForm()` and pass it to the templ ## Template -We need to create a file `post_edit.html` in the `blog/template/blog` directory. To make a form work we need several things: +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: - we need to display the form. We can do that for example with a `{{ form.as_p }}`. - the line above have to be wrapped with HTML form tag: <`form method="POST">...` @@ -149,7 +149,7 @@ The answer is: nothing. We need to do a little bit more work in our view. ## Saving the form -Open `blog/views.py` once again. Currently all we have in `post_new` view is: +Open `mysite/blog/views.py` once again. Currently all we have in `post_new` view is: def post_new(request): form = PostForm() @@ -221,7 +221,7 @@ Django is taking care of validating that all fields in our form are correct. Isn 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). -Open `blog/post_detail.html` and add this line: +Open `mysite/blog/post_detail.html` and add this line: @@ -240,13 +240,13 @@ so that the template will look like:

{{ post.text }}

{% endblock %} -In `blog/urls.py` we add this line: +In `mysite/blog/urls.py` we add this line: url(r'^post/(?P[0-9]+)/edit/$', views.post_edit, name='post_edit'), -We will reuse the template `blog/template/blog/post_edit.html`, so last the thing missing is a view. +We will reuse the template `mysite/blog/templates/blog/post_edit.html`, so last the thing missing is a view. -Let's open a `blog/views.py` and add at the very end of the file: +Let's open a `mysite/blog/views.py` and add at the very end of the file: def post_edit(request, pk): post = get_object_or_404(Post, pk=pk) diff --git a/django_models/README.md b/django_models/README.md index 8b9067f90e4..49ffae8bae8 100644 --- a/django_models/README.md +++ b/django_models/README.md @@ -77,7 +77,7 @@ You will notice that a new `blog` folder is created and it contains a number of ├── 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/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: +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: INSTALLED_APPS = ( 'django.contrib.admin', @@ -94,7 +94,7 @@ After creating an application we also need to tell Django that it should use it. In a file `models.py` 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: +Let's open `mysite/blog/models.py`, remove everything from it and write code like this: from django.db import models from django.utils import timezone diff --git a/django_orm_querysets/README.md b/django_orm_querysets/README.md index 4d6913ea53c..97976d1d76d 100644 --- a/django_orm_querysets/README.md +++ b/django_orm_querysets/README.md @@ -6,7 +6,7 @@ This is exactly what `views` are supposed to do: connect models and templates. I Ok, so how we will achieve it? -We need to open our `blog/views.py`. So far `post_list` view looks like this: +We need to open our `mysite/blog/views.py`. So far `post_list` view looks like this: from django.shortcuts import render @@ -54,7 +54,7 @@ The last missing part is to pass the `posts` queryset to the template (we will c 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}`. -So finally our `views.py` file should look like this: +So finally our `mysite/blog/views.py` file should look like this: from django.shortcuts import render from .models import Post diff --git a/django_templates/README.md b/django_templates/README.md index b296e5c59b9..01cac75313b 100644 --- a/django_templates/README.md +++ b/django_templates/README.md @@ -16,7 +16,7 @@ To print a variable in Django template, we use double curly brackets with the va {{ posts }} -Try this in your `post_list.html` template, save the file and refresh the page to see the results: +Try this in your `mysite/blog/templates/blog/post_list.html` template, save the file and refresh the page to see the results: ![Figure 13.1](images/step1.png) diff --git a/django_urls/README.md b/django_urls/README.md index 8adaa61d0fc..4a24424198e 100644 --- a/django_urls/README.md +++ b/django_urls/README.md @@ -12,7 +12,7 @@ Every page on the internet needs its own URL. This way your application knows wh ## How URLs work in Django? -Let's open up the `mysite/urls.py` file and see how it looks: +Let's open up the `mysite/mysite/urls.py` file and see how it looks: from django.conf.urls import patterns, include, url @@ -45,10 +45,10 @@ Do you wonder how Django matches URLs to views? Well, this part is tricky. Djang 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. -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. +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. Go ahead, delete comment lines and add a line that will import `blog.urls` into main url (`''`). -Your `mysite/urls.py` file should now look like this: +Your `mysite/mysite/urls.py` file should now look like this: from django.conf.urls import patterns, include, url diff --git a/extend_your_application/README.md b/extend_your_application/README.md index f39e267db18..0b883cb3e5f 100644 --- a/extend_your_application/README.md +++ b/extend_your_application/README.md @@ -10,7 +10,7 @@ We already have a `Post` model, so we don't need to add anything to `models.py`. ## Create a link in the template -We will start with adding a link inside `post_list.html` (in `blog/template/blog` directory) file. So far it should look like: +We will start with adding a link inside `mysite/blog/templates/blog/post_list.html` file. So far it should look like: @@ -97,7 +97,7 @@ The good news is that you actually can create your own `Page not found` page and Ok, time to add a view to our `views.py` file! -We should open `blog/views.py` and add the following code: +We should open `mysite/blog/views.py` and add the following code: from django.shortcuts import render, get_object_or_404 @@ -119,7 +119,7 @@ It worked! But what happens when you click a link in blog post title? Oh no! Error once again. But we already know how to deal with it, right? We need to add a template! -We will create a file in `blog/template/blog` called `post_detail.html`. +We will create a file in `mysite/blog/templates/blog` called `post_detail.html`. It will look like this: diff --git a/homework_add_more_to_your_website/README.md b/homework_add_more_to_your_website/README.md index ca27ee122f8..b5591143e20 100644 --- a/homework_add_more_to_your_website/README.md +++ b/homework_add_more_to_your_website/README.md @@ -12,11 +12,11 @@ Let's add a link in `mysite/templates/mysite/base.html` near the button for addi -Next: urls! In `blog/urls.py` we add: +Next: urls! In `mysite/blog/urls.py` we add: url(r'^drafts/$', views.post_draft_list, name='post_draft_list'), -Time to create a view in `blog/views.py`: +Time to create a view in `mysite/blog/views.py`: def post_draft_list(request): posts = Post.objects.filter(published_date__isnull=True).order_by('created_date') @@ -24,7 +24,7 @@ Time to create a view in `blog/views.py`: 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')`). -Ok, the last bit is of course a template! Create a file `blog/templates/blog/post_draft_list.html` and add the following: +Ok, the last bit is of course a template! Create a file `mysite/blog/templates/blog/post_draft_list.html` and add the following: {% extends 'mysite/base.html' %} @@ -48,7 +48,7 @@ Yay! First task is done! It would be nice to have a button on post detail page that will immediatelly publish the post, right? -Let's open `blog/template/blog/post_detail.html` and change these lines: +Let's open `mysite/blog/template/blog/post_detail.html` and change these lines: {% if post.published_date %} {{ post.published_date }} @@ -64,11 +64,11 @@ into these ones: 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 `Publish`. Note that we are passing a `pk` variable in the `{% url %}`. -Time to create a url (in `blog/urls.py`): +Time to create a url (in `mysite/blog/urls.py`): url(r'^post/(?P[0-9]+)/publish/$', views.post_publish, name='post_publish'), -and finally, a view (as always, in `blog/views.py`): +and finally, a view (as always, in `mysite/blog/views.py`): def post_publish(request, pk): 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! ## Delete post -Let's open `blog/templates/blog/post_detail.html` once again and add this line: +Let's open `mysite/blog/templates/blog/post_detail.html` once again and add this line: just under a line with edit button. -Now we need an url (`blog/urls.py`): +Now we need an url (`mysite/blog/urls.py`): url(r'^post/(?P[0-9]+)/remove/$', views.post_remove, name='post_remove'), -Now, time for a view! Open `blog/views.py` and add this code: +Now, time for a view! Open `mysite/blog/views.py` and add this code: def post_remove(request, pk): post = get_object_or_404(Post, pk=pk) diff --git a/starting_django_project/README.md b/starting_django_project/README.md index 9b40712ffd0..95b62c8cf6a 100644 --- a/starting_django_project/README.md +++ b/starting_django_project/README.md @@ -34,7 +34,7 @@ Let's ignore the other files for now - we will not change them, so we will skip ## Changing settings -Let's do some changes in `settings.py`. +Let's do some changes in `mysite/settings.py`. It would be nice to have a correct time on our website. You should find lines that contain `USE_TZ` and `TIME_ZONE` and change them to look like this: diff --git a/template_extending/README.md b/template_extending/README.md index f54119f08ad..0c312c633f0 100644 --- a/template_extending/README.md +++ b/template_extending/README.md @@ -52,7 +52,7 @@ Then in `base.html`, replace your whole `` with this: What does it mean? You just created a `block`, which is a template tag that allows you to insert HTML in this place in templates that are extending `base.html`. -Now save it, and open your `post_list.html` again. Delete everything else than what's inside the body: +Now save it, and open your `mysite/blog/templates/blog/post_list.html` again. Delete everything else than what's inside the body: