[Use it like this!] Configuration and utilization of Django development environment on the Naver Cloud Platform [1]

NAVER CLOUD PLATFORM
NAVER CLOUD PLATFORM
5 min readJun 2, 2020

* This content was created by Changan Song, a Naver Cloud Platform Tech Evangelist.

Greetings, this is Naver Cloud Platform.

Python, a development language that’s highly favored since it’s easy to learn and can be used in many fields!

Among them, Python-based Django is a web framework that allows you to develop websites quickly and easily.

In this post, I’ll talk about how to build a Django development environment using a server on the Naver Cloud Platform.

* There’ll be 2 episodes about this topic, so look forward to the next post.

Before we get started…

Q. What is Django?

Django is a free open-source web application framework created with Python. It is a web framework made up of components that help you develop a website quickly and easily. Django allows you to use a number of Python libraries, and it’s fast and easy to develop by using Python syntax.

Server creation and package installation

0. Creating a server of the Naver Cloud Platform

<manual Link>

The post below includes a guide for interworking with a DNS and public IP on Naver Cloud Platform.

(Link) Linkage with the Naver Cloud Platform’s DNS service, Server service, and public IP service

1. Install the Python package, pip-related Python package, and Python setuptools on the created server.

yum update python -y
yum install python-setuptools
curl -k -O https://bootstrap.pypa.io/get-pip.py
python get-pip.py

2. Install Django-related Python package.

pip install DjangoDEPRECATION: Python 2.7 will reach the end of its life on January 1st, 2020. Please upgrade your Python as Python 2.7 won’t be maintained after that date. A future version of pip will drop support for Python 2.7. More details about Python 2 support in pip, can be found at https://pip.pypa.io/en/latest/development/release-process/#python-2-support
Collecting Django
Downloading https://files.pythonhosted.org/packages/cf/19/632a613bc37bbf890f9323ba09374ce9af1d70bb4cba7ff4d3e5e0991b47/Django-1.11.26-py2.py3-none-any.whl (6.9MB)
|████████████████████████████████| 7.0MB 745kB/s
Collecting pytz
Downloading https://files.pythonhosted.org/packages/e7/f9/f0b53f88060247251bf481fa6ea62cd0d25bf1b11a87888e53ce5b7c8ad2/pytz-2019.3-py2.py3-none-any.whl (509kB)
|████████████████████████████████| 512kB 38.6MB/s
Installing collected packages: pytz, Django
Successfully installed Django-1.11.26 pytz-2019.3

3. Enter print (django.get_version()) in the command shell as shown below to check the Django version. Also, make sure that the current version is 1.11.26.

# python
Python 2.7.5 (default, Aug 7 2019, 00:51:29)
[GCC 4.8.5 20150623 (Red Hat 4.8.5–39)] on linux2
Type “help”, “copyright”, “credits” or “license” for more information.
>>> import django
>>> print(django.get_version())
1.11.26

4. Install MariaDB on the host to connect Django and MariaDB. Activates and starts the daemon on bootup (Django’s default setting is SQLite).

yum install -y mariadb mariadb-server mariadb-devel
systemctl enable mariadb.service
systemctl start mariadb.service

5. Install MySQL-related Python package.

pip install mysql-pythonDEPRECATION: Python 2.7 will reach the end of its life on January 1st, 2020. Please upgrade your Python as Python 2.7 won’t be maintained after that date. A future version of pip will drop support for Python 2.7. More details about Python 2 support in pip, can be found at https://pip.pypa.io/en/latest/development/release-process/#python-2-support
Collecting mysql-python
Using cached https://files.pythonhosted.org/packages/a5/e9/51b544da85a36a68debe7a7091f068d802fc515a3a202652828c73453cad/MySQL-python-1.2.5.zip
Building wheels for collected packages: mysql-python
Building wheel for mysql-python (setup.py) … done
Created wheel for mysql-python: filename=MySQL_python-1.2.5-cp27-cp27mu-linux_x86_64.whl size=84386 sha256=0d38521d6f79e9aa3f620ad88e1d9245001743e4d67ed421f1d9e0128640f60f
Stored in directory: /root/.cache/pip/wheels/07/d2/5f/314860e4cb53a44bf0ee0d051d4b34465e4b4fbe9de6d42f42
Successfully built mysql-python
Installing collected packages: mysql-python
Successfully installed mysql-python-1.2.5

6. Start a new Django project. In the current example, it will be specified as dasvader.

django-admin.py startproject dasvader

7. The new project will proceed with a basic setup in dasvader.

In the example, the list allowed when linking dasvader with MariaDB and accessing it from an external environment will be designated.

vim dasvader/settings.pyDATABASES = {
‘default’: {
‘ENGINE’: ‘django.db.backends.mysql’,
‘NAME’: ‘djangotest’,
‘USER’: ‘csong’,
‘PASSWORD’: ‘djangotest’,
‘HOST’: ‘’,
‘PORT’: ‘’,
}
}
DATABASE_OPTIONS = {‘charset’: ‘utf8’}
LANGUAGE_CODE = ‘ko-kr’
TIME_ZONE = ‘Asia/Seoul’
….
ALLOWED_HOSTS = [“example.csong.kr”,”106.10.40.78"]

8. After the setup is complete, begin syncing dasvader with the database through the “python manage.py migrate” command.

python manage.py migrateSystem check identified some issues:
WARNINGS:
?: (mysql.W002) MySQL Strict Mode is not set for database connection ‘default’
HINT: MySQL’s Strict Mode fixes many data integrity problems in MySQL, such as data truncation upon insertion, by escalating warnings into errors. It is strongly recommended you activate it. See: https://docs.djangoproject.com/en/1.11/ref/databases/#mysql-sql-mode
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 sessions.0001_initial… OK

9. Create users in the project and designate them to access the admin page.

python manage.py createsuperuser
Username (leave blank to use ‘root’): admin
Email address: admin@csong.kr
Password: test1111
Password (again): test1111
Superuser created successfully.

10. Run the project on the current test server and make it accessible from an external environment.

python manage.py runserver 0.0.0.0:8000

11. After connecting the executed server at http://example.csong.kr:8000/ from an external environment, you can see that the new page can be accessed normally.

References

Before we go…

In this post, we learned how to create a server through the Naver Cloud Platform services, as well as how to install and configure Django-related packages on the server.

In the next post, we’ll learn how to build a REST API server using Django.

We’ll be back with more useful content in the future. Thank you.

--

--

NAVER CLOUD PLATFORM
NAVER CLOUD PLATFORM

We provide cloud-based information technology services for industry leaders from startups to enterprises.