Django is an open source web application framework. It helps building your website faster and easier.
While building a website, there’s always a must-develope forms:
- user certificate
- website admin
- file upload
etc…
what is a framework? why using this?
framework can be called a program structure.
It has lots of utilites to help concentrate fully on implementation. These frameworks provide a structure for those must-develope forms above.
But it is crucial to remind that framework is only a base structure, and doesn’t execute by itself. we need to add functions while obeying framework rules.
there’s lots of framework. Typically,
- Python Developer: Django
- Javascript Developer: Angularjs
- Java Developer: Spring
tutorial: make Django blog site
- activate virtualenv
1
source [venvname]/bin/activate
- start project
django-admin.py create directories and files using script1
(venvname) ~/django$ django-admin startproject mysite .
After run script, you’ll see directory structure as below
1 2 3 4 5 6 7
~/django /manage.py #script that helps manage site. without any installation it makes web server starts. /mysite /-settings.py #website settings file /urls.py #include pattern list that urlresolver uses /wsgi.py /__init__.py
- modify setting
Let’s modify mysite/settings.py a bit.
website needs exact current time. copy-paste your timezone1
TIME_ZONE = 'Asia/Seoul'
next, include static file path
1 2
STATIC_URL = '/static/' STATIC_ROOT = os.path.join(BASE_DIR, 'static')
If DEBUG==TRUE and ALLOWED_HOSTS is empty, it is valid for [‘localhost’, ‘127.0.0.1’, ‘[::1]’].
1
ALLOWED_HOSTS = ['127.0.0.1', '.pythonanywhere.com']
- database setting
we’ll use sqlite3 among lots of DBs. sqlite3 already installed in mysite/settings.py1 2 3 4 5 6
DATABASES = { 'default': { 'ENGINE': 'django.db.backends.sqlite3', 'NAME': os.path.join(BASE_DIR, 'db.sqlite3'), } }
- create database
In order to create database in website, run following code on bash.1
(virtualvenv) ~/django$ python manage.py migrate
- runserver
Now let’s start web server to check whether website runs normal.1
(virtualvenv) ~/django$ python manage.py runserver
- open your web browser
type http://127.0.0.1:8000/
you’ll see the sign “It worked!”
원본 링크: https://tutorial.djangogirls.org/ko/