Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

The method of creating a django project using vscode

2025-04-03 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/02 Report--

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.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 219

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report