Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions css/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,21 +52,21 @@ 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;
}

`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 %}

Expand All @@ -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 `<head>` in `post_list.html` file:
Maybe we can customize the font in our header? Paste this into your `<head>` in `mysite/blog/templates/blog/post_list.html` file:

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

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;
Expand All @@ -121,7 +121,7 @@ And now add a class `post` to your `div` containing blogposts.
<p>{{ post.text }}</p>
</div>

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;
Expand Down Expand Up @@ -181,7 +181,7 @@ Then also replace this:
</div>
{% endfor %}

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

<div class="content">
<div class="row">
Expand Down
8 changes: 4 additions & 4 deletions deploy/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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
Expand All @@ -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()

Expand All @@ -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__
Expand Down
2 changes: 1 addition & 1 deletion django_admin/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
20 changes: 10 additions & 10 deletions django_forms/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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`:

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

Expand Down Expand Up @@ -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),

Expand All @@ -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

Expand All @@ -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">...</form>`
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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:

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

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

In `blog/urls.py` we add this line:
In `mysite/blog/urls.py` we add this line:

url(r'^post/(?P<pk>[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)
Expand Down
4 changes: 2 additions & 2 deletions django_models/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions django_orm_querysets/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion django_templates/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
6 changes: 3 additions & 3 deletions django_urls/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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

Expand Down
6 changes: 3 additions & 3 deletions extend_your_application/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:

<html>
<head>
Expand Down Expand Up @@ -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

Expand All @@ -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:

Expand Down
18 changes: 9 additions & 9 deletions homework_add_more_to_your_website/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,19 @@ Let's add a link in `mysite/templates/mysite/base.html` near the button for addi

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

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')
return render(request, 'blog/post_draft_list.html', {'posts': posts})

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' %}

Expand All @@ -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 }}
Expand All @@ -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 `<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 %}`.

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

url(r'^post/(?P<pk>[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)
Expand All @@ -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:

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

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<pk>[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)
Expand Down
2 changes: 1 addition & 1 deletion starting_django_project/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:

Expand Down
2 changes: 1 addition & 1 deletion template_extending/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ Then in `base.html`, replace your whole `<body>` 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:

<div class="page-header">
<h1><a href="">Django Girls Blog</a></h1>
Expand Down