1.4 KiB
1.4 KiB
django girls blog
Target: create a blog using django.
01 Your first Django project!
1.1 Create Django project
- Command to start Django project:
$ django-admin startproject mysite.
Generating following dir structure:
djangogirls
├── manage.py
├── mysite
│ ├── __init__.py
│ ├── settings.py
│ ├── urls.py
│ └── wsgi.py
├── myvenv
│ └── ...
└── requirements.txt
where:
setting.py
L: helps with management of the site.- contains configuration of the website
urls.py
: contains a list of patterns used byurlresolve
1.2 Change settings of django website
Edit mysite/settings.py
:
- Change timezone: `TIME_ZONE=Australia/Canberra'
- Change language: `LANGUAGE_CODE = 'en-us'
- Add a path for static files (e.g. CSS and static files):
STATIC_ROOT = os.path.join(BASE_DIR, 'static')
- Add allowed host site:
ALLOWED_HOST = ['127.0.0.1', '.amazonaws.com']
for using cloud9
1.3 Set up a database
Django support multiple databases, to store data. sqlite3
is the default one, which is already set up as shown in mysite/settings.py
:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': BASE_DIR / 'db.sqlite3',
}
}
After confirming database settings, migrate the project python manage.py migrate
1.4 Starting the web server
python manage.py runserver