Django and TEJ API (Part 1)

Use Python Django to create a website

Photo by Carlos Muza on Unsplash

Highlights

  • Difficulty:★☆☆☆☆
  • Django development setting
  • Advice: This series of articles aims to introduce the common application of Django modules and how it can be used with TEJ API database. Thus, we’ll not dive into the detailed functions or the knowledge of a webpage’s front-end and back-end. If readers are interested in what was mentioned above, you can refer to this document, which explains the details quite well

Preface

Django is a Python-based application framework of web. Since it has advantages such as fixed framework and abundant libraries, users can develop a website in a more straightforward and efficient way.

In this series, we’ll cover the topics including the setting of Django, framework introduction, connection of TEJ API database, creation of back-end database, the usage of css and js and converting django project to exe file. We’ll guide the readers step by step to build something like the picture shown below. And in this week, we are going to elaborate how to set Django development environment properly to avoid annoying errors in the future.

The Editing Environment and Modules Required

Windows OS and Visual Studio

Virtual Environment

Step 1. Enter into Visual Studio and open newly-created file (medium)

Step 2. Add a terminal and type python -m venv (your_env_name) to create a virtual environment. The purpose of this step is to avoid different versions of modules might have some conflicts and some errors will somehow occur.

Step 3.Type(your_env_name)\Scripts\activate to enter into virtual environment. If there’s green word showing up, meaning you are correctly in a virtual environment. Then you can start to install Django module by using pip. Remember each time you go into this project and install any modules, you should always enter the virtual environment first.

Start a Project

Step 1. Type django-admin.py startproject (your_project_name)in terminal. The a project file (finance) will occur under the project file(medium). The current structure of files is shown on the left hand side

Step 2. Move to the project file and type python manage.py runserver (port), which will activate a simple web server. The port is set 8000 by default and you can change it according to your perference

Step 3. Click the link and you can see it’s successfully launched

Add a New Application (app)

When the project is complicated, we usually divide it into different applications. Thus, we also need some applications under the project file.

Step 1. If you don’t want to terminate the web server, you can add another terminal and make sure you’re in virtual environment by identifying the green words. Next, move to project file and type python manage.py startapp dashboard to create your first app. Here we name it as dashboard, and then the app file (dashboard) will show up right under the project file (finance)

Step 2. To notify Django that the new app should also be under control, we need to add something in setting file. The setting file is called setting.py and located in “finance\finance\settings.py”.。Then find the INSTALLED_APPS block and add your app name at the end of the list.

Step 3. Current structure of the project

finance
├── manage.py
├── finance
│ ├── __init__.py
│ ├── settings.py
│ ├── urls.py
│ └── wsgi.py
└── dashboard
├── __init__.py
├── admin.py
├── migrations
├── models.py
├── tests.py
└── views.py

Conclusion

This article mainly introduces how to set Django development environment, such as virtual environment, project and applications. Some details shouldn’t be ignored like entering into virtual environment, familiar with project structure and change of setting file. Otherwise, it will trigger many problems. That’s why we write this article to make sure everything is in place, and then we can start to build our finance-related webpage in our next article !

Extended Reading

Related Link

Back
Procesing