Set up python and pip on linux system for correct django version.
You can see here:
https://docs.djangoproject.com/ko/2.0/faq/install/
In this case, I will use Python 3.6 and Django 2.0
-Upgrade pip tool
# pip install --upgrade pip
-Installing Django
# pip install django~=2.0.5
-Starting the project
(env) # django-admin startproject project_name .
In the project
dir .
ㄴmanage.py
ㄴproject_name
ㄴsettings.py
ㄴurls..py
ㄴwsgi.py
ㄴ__init__.py
manage.py: A script for managing web app
settings.py: Configuration of website
urls.py: Pattern list which is used by urlresolver
-settings.py: add or edit few lines on it.
In this case, I'm going to use Mariadb on local server for django database.
...
#DATABASE
DATABASES = {
'default': {
#'ENGINE': 'django.db.backends.sqlite3',
#'NAME': os.path.join(BASE_DIR, 'db.sqlite3'
'ENGINE': 'django.db.backends.mysql',
'NAME': 'django',
'USER': 'mariadb',
'PASSWORD': 'mariadb',
'HOST': 'localhost',
'PORT': '3306',
}
}
...
TIME_ZONE = 'Asia/Seoul'
...
STATIC_ROOT = os.path.join(BASE_DIR, 'static')
-Install mariadb
$ sudo yum install -y mariadb-server
$ sudo mysql_secure_installation
$ systemctl start mariadb
1 2 3 | [user1@django ~]$ mysql -u root -p Enter password: | cs |
1 2 3 4 5 6 7 8 9 10 11 12 | MariaDB [(none)]> CREATE database db_name; Query OK, 1 row affected (0.01 sec) MariaDB [(none)]> CREATE user 'user_name'@'localhost' identified by 'user_passwd'; Query OK, 0 rows affected (0.00 sec) MariaDB [(none)]> GRANT ALL on db_name.* TO 'user_name'@'localhost'; Query OK, 0 rows affected (0.00 sec) MariaDB [(none)]> FLUSH PRIVILEGES; Query OK, 0 rows affected (0.00 sec) | cs |
-After editing settings.py
(env) # python manage.py migrate
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | (djenv) [user1@django django]$ python manage.py migrate Operations to perform: Apply all migrations: admin, auth, contenttypes, sessions Running migrations: Applying contenttypes.0001_initial... OK Applying auth.0001_initial... OK Applying admin.0001_initial... OK Applying admin.0002_logentry_remove_auto_add... OK Applying contenttypes.0002_remove_content_type_name... OK Applying auth.0002_alter_permission_name_max_length... OK Applying auth.0003_alter_user_email_max_length... OK Applying auth.0004_alter_user_username_opts... OK Applying auth.0005_alter_user_last_login_null... OK Applying auth.0006_require_contenttypes_0002... OK Applying auth.0007_alter_validators_add_error_messages... OK Applying auth.0008_alter_user_username_max_length... OK Applying auth.0009_alter_user_last_name_max_length... OK Applying sessions.0001_initial... OK | cs |
-Test my django web application
(env) # python manage.py runserver
1 2 3 4 5 6 7 8 9 10 11 12 13 | (djenv) [user1@django django]$ python manage.py runserver Performing system checks... System check identified no issues (0 silenced). May 28, 2018 - 18:02:55 Django version 2.0.5, using settings 'asset_mngr.settings' Starting development server at http://127.0.0.1:8000/ Quit the server with CONTROL-C. [28/May/2018 18:03:44] "GET / HTTP/1.1" 200 16348 [28/May/2018 18:03:44] "GET /static/admin/css/fonts.css HTTP/1.1" 200 423 [28/May/2018 18:03:44] "GET /static/admin/fonts/Roboto-Regular-webfont.woff HTTP/1.1" 200 80304 [28/May/2018 18:03:44] "GET /static/admin/fonts/Roboto-Bold-webfont.woff HTTP/1.1" 200 82564 [28/May/2018 18:03:44] "GET /static/admin/fonts/Roboto-Light-webfont.woff HTTP/1.1" 200 81348 | cs |
'Python' 카테고리의 다른 글
Flask on apache via mod_wsgi (0) | 2018.12.06 |
---|---|
Python 2.6 to 2.7 (or 3.x) (0) | 2018.11.23 |
Django: 1. Start first application (0) | 2018.05.30 |
파이썬 장단점 (0) | 2018.05.24 |
Set up Python 3 on the CentOS 7 (1) | 2016.01.29 |