Steps and Methods of Creating Django Project in pycharm

  • 2021-09-12 01:39:00
  • OfStack

When we use the editor, we want to add an Django project to it, so that we can do the desired operation in it. Some people haven't installed Django yet, so you can solve it directly from the command line. Then, in the specific steps of building a new project, this article has been sorted out in detail. For small partners who want to build a new project in pycharm, let's take a look at the specific process.

1. Before creating the project, we should install Django and install the command line


pip install django==1.11

The following numbers indicate the specified version number. Remember that 1 must be equal to two.

2. Create the virtual environment of Django and create the project directory (** Note: ** Create the Django project with PyCharm under Windows, and both the virtual environment and directory are created directly, so these two steps can be omitted);

3. Create Django project directly in PyCharm and select File-- > New Project-- > Django-- > Loaction-- > Your own project name- > Create, so the project is created, as shown below. My project name is First_Project First_Project. png

4. After creating the project, we create a test test. py file in the project, enter an print ("hello") to try, and then run test. py: Right-click- > Select the run project name, whether the console will output 1 hello ah.

5. To run the entire Django project, we can: select Run-- > Run-- > Your project name is OK, and the console is displayed as follows: console. png

6. In addition, we can also configure IP and Port of Django server and select Run- > Click Edit Configurations to configure the port you want. (You can choose a number between 1 and 65535, preferably 80, but sometimes using 80 will conflict, so use 8080 or 8081).

Django project field explanation:

1. manage. py is an administrative role

Features include:

(1) Create app: python manage. py startapp miaTest where startapp is the command and miaTest is the name of app

(2) Manage the database
Python manage. py sqlall miaTest: Look at all the tables below miaTest this app
Python manage. py syncdb: Synchronizing databases

(3) Management Server
Python manage.py runserver ip:port- > Change the accessed ip and port number

2. Venv

To use django, first of all, we need to build a virtual working environment, in which we can install packages and isolate them from other projects. It mainly solves the problem of version and dependency in the process of Python software development, so that each project has its own independent installation directory ring

3.mySite2

(1) init. py: This file is empty by default. Only when this file is defined, the python virtual machine will consider the current folder as a legal package, and the Python program under the representative directory is a part of module. So it is the identity of package
(2) Settings. py: Including app path, database configuration, sql statement, static file directory, middleware, session storage related configuration
(3) Urls. py: Entry to all URLs, associated with functions in views
(4)Wsgi.py

4.Templates

Mainly by html code and logic control block code.


Related articles: