Use Python Django to create a website
Table of Contents
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.
Windows OS and Visual Studio
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.
(your_env_name)\Scripts\activateto 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.
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
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
When the project is complicated, we usually divide it into different applications. Thus, we also need some applications under the project file.
python manage.py startapp dashboardto 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)
│ ├── __init__.py
│ ├── settings.py
│ ├── urls.py
│ └── wsgi.py
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 !