Hello everyone, I am my cousin who loves cats and technology. This series will update my study notes of my blog project, which is also a focus of the later update. I hope my personal blog page can meet with you as soon as possible.

Install the Python environment

Here I chose to download the latest version of Python, which can be downloaded directly from the browser at the address below. Of course, you can download other versions (level 3.7 and above is fine), but the advice is consistent with the blogger. www.python.org/downloads/r…

After downloading, you can install it directly.Test run, direct terminal inputpython3.10Can enter, as shown in the picture, normal entry is no problem.If Windows is used, you need to configure environment variables in python3.10. You can search for how to configure environment variables in the browser.

Looking at the PIP version, you can see that the original PY3.7 and the current Py3.10 in the system do not interfere with each other.

Create a virtual environment, install Django, and create a Django project

Create a virtual environment, here we use pipenv for virtual environment management, if you have not installed pipenv direct terminal can run the following command:

Pip3.10 install pipenvCopy the code

With pipenv installed, we go to the project directory and install the virtual environment:

cd Project && mkdir brief_blog
cdBrief_blog pipenv install - python3.10Copy the code

After installing the virtual environment, go to the virtual environment and install Django. Here, we will install Django directly. The default version is 3.2.8.

pipenv shell
pip install django
Copy the code

Once django is installed, we quickly create a Django project using the django-admin command,

django-admin startproject myblog
Copy the code

Once I’ve created it, it will automatically create a myBlog folder for me, so let’s go into the project directory and look,

cd myblog
ls
Copy the code

  • The external myBlog/root directory is the outermost directory of the project. Its name isn’t important to Django; you can rename it to whatever you like, preferably relevant to your project.
  • Manage.py: a command-line utility that lets you interact with this Django project in various ways. Using detailed introduction can view the document: docs.djangoproject.com/en/3.2/ref/…
  • Db.sqlite3: Default Django projects use sqLite databases by default.
  • Myblog /__ init__. Py: an empty file that tells Python that the directory should be considered a Python package (to be used later by other modules in the import project).
  • Myblog/ASgi.py: ASGI is an interface to an asynchronous Web server that serves a project.
  • Myblog /settings.py: The Settings file for this Django project. Including database, APP registration, constant Settings, etc.
  • Myblog /urls.py: The URL (route) declaration file for this Django project.
  • Myblog /wsgi.py: Python server gateway interface. It is the interface between Python applications and Web servers for deploying and launching Django projects on the server.

To test run the project we created,

python manage.py runserver
Copy the code

You’ll notice the screenshot in red:18 unapplied migration(s)There are 18 useless applications migration, in order not to affect the later use we can execute the following command to migrate applications, we will often use this command in the later, which makes our operation with the database more convenient.

python manage.py migrate
Copy the code

After the migration is complete, we will not be prompted when we execute the following command, use a browser to visit http://127.0.0.1:8000, and the following page will be displayed indicating that the project is ok.

python manage.py runserver
Copy the code

At the terminal, we hold CTRL + C to terminate the program.

Next, we will enter VS Code to write the project code.

Install & use VS Code

In order to make it easier to learn and write code, it is necessary to install a good development tool. I checked it on the Internet and finally chose VS Code. The main reason is that vs Code is open source and free, and there are many plug-ins.

Base installation

Official website download address:code.visualstudio.com/ Select the system and download the stable version.

Download good, unzip after the direct click can open the use, do not install, can also install Chinese language package, direct interface Chinese, use more convenient.

Loved it so much, installed a lot of toolkits:

shortcuts

Ctrl/Command+P to quickly bring up the query window to find files, Ctrl/Command+Shift+P to quickly bring up the Command window to do things like snippets, Set shortcut code block Ctrl/Command+Shift+M Quickly display "Problem" panel Ctrl/Command+H Find replace Ctrl/Command+Shift+F Find in the entire folder Ctrl + ~ Bring up terminal or hide Ctrl/Command + +/- Zoom in/out... It will be added later if it is usefulCopy the code

Import the project and set up the Python interface

After opening vscode, click file – open folder in the navigation bar and select the project directory to open it.

After importing the project, configure the operating environment of the project first and holdCtrl/Command+Shift+PAnd then typePython: Select Interpreter, click to enter python interface selection.Select our new virtual environment,

Run the project

Click vscode in the navigation barrun->Add the configuration.The following window appearsSelect debug Configuration, we select the line from Django.Then we can press the shortcut keyctrl+f5Running the program will automatically bring up the terminal and run runServer. In fact, we can also directly bring up the terminal and run the relevant commands after entering the virtual environment.

This concludes the first section, in which you learned how to install the python environment, create a virtual environment, install django packages, create a django project, install vscode, and run projects in it.

This plays a very good foundation for the study behind, we come on together ~

Hello everyone, I am old cousin, love cat love technology, pay attention to me, progress together.