Skip to content

Commit c8f4ae0

Browse files
committed
Chapter about installing Django and how to start Django project.
1 parent 79fc8ee commit c8f4ae0

4 files changed

Lines changed: 121 additions & 5 deletions

File tree

SUMMARY.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,6 @@
55
* [Introduction to Python](try_python/README.md)
66
* [What is Django?](django_-_why_you_need_a_webframework/README.md)
77
* [Django installation](django_installation/README.md)
8+
* [Starting Django project](starting_django_project/README.md)
89
* [Next chapters](next_chapters/README.md)
910

django_installation/README.md

Lines changed: 35 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,23 +8,54 @@ Before we will install Django, we will make you install something very handy and
88

99
That's why we want you to create a Virtual environment (also called `virtualenv`). It will isolate things you do from your computer, so you will have everything important in one place. Neat, right?
1010

11-
All you need to do is find a folder in which you want to create the `virtualenv`, for example your home directory. In Windows it could look like: `C:\Users\Ala\` (where Ala is the name of the user).
11+
All you need to do is find a folder in which you want to create the `virtualenv`, for example your home directory. In Windows it could look like: `C:\Users\Name\` (where `Name` is a name of the user).
1212

1313
### Windows
1414

1515
To create `virtualenv` you need to open command line `cmd` and type there `C:\Python\python -m venv blog`. It will look like this:
1616

17-
C:\Users\Ala> C:\Python34\python -m venv blog
17+
C:\Users\Name> C:\Python34\python -m venv blog
1818

1919
where `C:\Python34\python` is folder in which you previously installed Python and `blog` is a 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 :).
2020

21-
### Linux
21+
### Linux and OS X
2222

23-
### OS X
23+
Creating `virtualenv` in both Linux and OS X is as simple as typing in console (remember, that we expect that you have python 3.4 installed):
2424

25+
~$ python -m venv blog
2526

27+
### Working with virtualenv
2628

29+
The command above will create a folder `blog` that contains our virtual environment (basically bunch of folders and files). All we want to do now is starting it by:
2730

31+
C:\Users\Name> blog\Scripts\activate
2832

33+
for Windows users, or:
34+
35+
~$ source blog/bin/activate
36+
37+
You will know that you have `virtualenv` started when you see that the prompt in your command line or console looks like:
38+
39+
(blog) C:\Users\Name>
40+
41+
or:
42+
43+
(blog) ~$
44+
45+
so the prefix `(blog)` appears!
46+
47+
Ok, we have all important things in place. We can finally install Django!
48+
49+
## Installing Django
50+
51+
Now, when you have your `virtualenv` started, you can install Django using PIP. In console/command-line you type `pip install django==1.6.4`.
52+
53+
(blog) ~$ pip install django==1.6.4
54+
Downloading/unpacking django==1.6.4
55+
Installing collected packages: django
56+
Successfully installed django
57+
Cleaning up...
58+
59+
That's it! Now you are finally ready to create a Django application.
2960

3061

install_python/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ Python was conceived in the late 1980s and it's main goal is to be readable by h
1010

1111
*This subchapter is based on awesome tutorials by Geek Girls Carrots (http://django.carrots.pl/)*
1212

13-
Django is written in Python. We need it to do anything in Django. Let's start with installing it!
13+
Django is written in Python. We need it to do anything in Django. Let's start with installing it! We want you to install Python 3.4, so if you have any earlier version, you will need to upgrade it.
1414

1515
### Windows
1616

starting_django_project/README.md

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
# Starting Django project
2+
3+
*This chapter is based on awesome tutorials by Geek Girls Carrots (http://django.carrots.pl/) and django-marcador (http://django-marcador.keimlink.de/).*
4+
5+
Let's build a simple blog!
6+
7+
The first step to create it is starting a new Django project. Basically that means that we will run some script from Django that will create for us a skeleton of Django project: bunch of directories and files that we will later use.
8+
9+
Names of some files and directories are very important for Django. You should not rename files that we are about to create. Moving them to different place is also not a good idea. Django needs a certain folder/files structure to be able to find important things.
10+
11+
In console/command-line you should type:
12+
13+
(blog) ~$ django-admin.py startproject mysite
14+
15+
`django-admin.py` is a script that will create folders and files for you. It should look like this:
16+
17+
mysite
18+
│ manage.py
19+
20+
└───mysite
21+
settings.py
22+
urls.py
23+
wsgi.py
24+
__init__.py
25+
26+
27+
`manage.py` is a script that helps with administration of the page. Thanks to it we will be able to start a web server on our computer without installing anything else.
28+
29+
File `settings.py` contains a configuration of your website.
30+
31+
Remember when we talked about a postman checking where to deliver a letter? `urls.py` file contains a list of patterns used by `urlresolver`.
32+
33+
Let's ignore for now other files - we will not change them, so we will skip expalining what they actually do. The only thing to remember is to not delete them by accident!
34+
35+
## Changing settings
36+
37+
Let's do some changes in `settings.py`.
38+
39+
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:
40+
41+
USE_TZ = False
42+
TIME_ZONE = 'Europe/Berlin'
43+
44+
## Creating a database
45+
46+
Most of web application have their own database. Database is a collection of data. This is a place in which you will store all information about users, all your blog post texts, etc..
47+
48+
There is number of different database systems that store data for you. We will use one of the simpliest: `sqlite3`, which was installed with Django. But if you plan to do some serious websites in a future we recommends looking at `PostgreSQL`.
49+
50+
To create a database for our blog we will type in console/command-line `python manage.py syncdb`. It should look like this:
51+
52+
(blog) ~/carrots$ python manage.py syncdb
53+
Creating tables ...
54+
Creating table auth_permission
55+
Creating table auth_group_permissions
56+
Creating table auth_group
57+
Creating table auth_user_groups
58+
Creating table auth_user_user_permissions
59+
Creating table auth_user
60+
Creating table django_content_type
61+
Creating table django_session
62+
Creating table django_site
63+
Creating table django_admin_log
64+
65+
You just installed Django's auth system, which means you don't have any superusers defined.
66+
Would you like to create one now? (yes/no): yes
67+
Username (leave blank to use 'Name'):
68+
Email address: admin@example.com
69+
Password:
70+
Password (again):
71+
Superuser created successfully.
72+
Installing custom SQL ...
73+
Installing indexes ...
74+
Installed 0 object(s) from 0 fixture(s)
75+
76+
It will ask you if you want to create a superuser. Type `yes`, press Enter and type your username (lowercase, no spaces), email address and password when you will be asked to type it.
77+
78+
And you are done. Time to start web server and see if our website is working!
79+
80+
You need to be in a folder that contains `manage.py` file (in `mysite` directory). In console/command-line we will start the web server by typing `python manage.py runserver`:
81+
82+
(blog) ~/mysite python manage.py runserver
83+
84+

0 commit comments

Comments
 (0)