Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

The method of creating a django project using vscode

Shulou Source: shulou.com Published: 2022-06-02 17:51:40 10月18日 Update

This article will explain in detail how to use vscode to create a django project. The editor thinks it is very practical, so I share it for you as a reference. I hope you can get something after reading this article.

I. preliminary preparatory work

1. Install Python, install pylint and yapf using pip:

Pip install pylint yapf

2. Download and install vscode: https://code.visualstudio.com/

3. Install the plug-in Python (official release of Microsoft). Click reload after installation to restart vscode and activate the Python plug-in

When you write the code after installing flake8, the editor will prompt you where something went wrong, and the code format will also be prompted.

1. Open the command line

2. Enter pip install flake8

3. After installing flake8 successfully, open VScode, File-> preferences-> user Settings, and enter "python.linting.flake8Enabled": true in the settings.json file.

II. Vs code configure Python environment]

The settings in settings.json are as follows:

Third, create a new Django project

Open the newly created file using vs code, as follows:

Open the Terminal window of vs code, change the path to the project path, and execute the following command:

Django-admin startproject project_name

Continue with the following command:

Python manage.py startapp app_name

Note:

(1) HelloWorld: the container of the project

(2) manage.py: a practical command line tool that allows you to interact with the Django project in a variety of ways.

(3) HelloWorld/init.py: an empty file that tells Python that the directory is a Python package

(4) HelloWorld/settings.py: the setting / configuration of the Django project.

(5) HelloWorld/urls.py: the URL statement of the Django project, a website "directory" driven by Django

(6) HelloWorld/wsgi.py: an entry to a WSGI-compatible Web server to run your project

4. Vs code configure Debug Django environment

The settings in launch.json are as follows:

{/ / use IntelliSense to learn about the relevant properties. / / hover to see a description of an existing property. "version": "0.2.0", "configurations": [{"name": "Python: Current File (Integrated Terminal)", "type": "python", "request": "launch", "program": "${file}", "console": "integratedTerminal"} {"name": "Python: Attach", "type": "python", "request": "attach", "port": 5678, "host": "localhost"} {"name": "Python: Module", "type": "python", "request": "launch", "module": "enter-your-module-name-here", "console": "integratedTerminal"} {"name": "Python: Django", "type": "python", "request": "launch", "program": "${workspaceFolder} / HelloWorld/manage.py", "console": "integratedTerminal" "args": ["runserver", "8080", / / configure Django port "--noreload", "--nothreading"], "django": true} {"name": "Python: Flask", "type": "python", "request": "launch", "module": "flask" "env": {"FLASK_APP": "app.py"}, "args": ["run", "--no-debugger" "--no-reload"], "jinja": true}, {"name": "Python: Current File (External Terminal)", "type": "python", "request": "launch" "program": "${file}", "console": "externalTerminal"}]} V. View effect by browser

On the use of vscode to create django project methods to share here, I hope that the above content can be of some help to you, can learn more knowledge. If you think the article is good, you can share it for more people to see.

Tags: Project command file configuration method utility code properties plug-in more environment directory article path prompt input good success entry content Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Information Xiaomi Apple Microsoft Huawei