程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式師世界 >> 編程語言 >  >> 更多編程語言 >> Python

About the creation of Django engineering project

編輯:Python

What is the Django?

Django Is an open source Web Application framework , Yes Python It's written in . It was originally developed to manage some of the Lawrence group's Focus on news content Web site . -- Baidu Encyclopedia

Use Django Most web sites are used for content management systems , Compared with Flask( the other one PythonWeb frame ), He is a heavy frame , Can do almost anything .

that django How to create it ?

  1. Learn how to create django Before project construction , We need to understand the virtual environment first (virtual environment) This thing

    Popular speaking , When developing multiple projects , Each project has its own modules , We can't put them all in one place , For example, I used in this project django The version is 2.2, And the version used in the other project does 3.1, That would create chaos , It is not convenient for the packaging and release of products . Virtual environment can be understood as a small square in a large wardrobe , You put down your clothes for tomorrow in this square , Put down your daily allowance in another box .

How do we install the virtual environment ?

  • First of all, make sure that our computer is installed with Python Of , And the system environment variables of the computer ( My computer — Right click , attribute — Advanced system setup — environment variable ) Configured Python The path of

    If there is , It proves that we have the ability to install python Virtual environment conditions ! It shows that it has been successful 1/4.

  • Next , Prepare a folder , Used to store our Django Engineering documents , Create a new folder in this folder , Name yourself .

  • Open the system terminal


    For example, I store my system D disc :

    Input d: After entering D disc , Then input cd Python/Django/one The yellow font is the location of my project folder

    What we need to do next is to create a virtual environment under this path , In the future, when we create another project, we can create a virtual environment in the new folder

  • Installing a virtual environment

    Enter... In the current path pip3 install virtualenv( If the computer has only python3, be 3 No , Direct input pip install virtualenv
    When the loading is completed, the download is successful !
    Next, enter... Under the path :

    two Environment name , Unfixed , Just remember , Something will jump out , It indicates that the creation is successful

    Then the name of your newly created virtual environment will appear in front of the original path

    To exit the virtual environment, enter :deactivate that will do
    Enter again workon two that will do
    This completes the download and creation of our virtual environment

The next step is to create a new django Project

  1. In New django Before the project , We need to download in the virtual environment we just created django modular , As for what version to use , You can go to django Official website see
    Get into DOWNLOAD Next , There will be such a picture

    This chart shows some of the versions recommended today ,LTS Express Long term update maintenance version , That is, within the above time , The official will be responsible for bug For maintenance , Generally choose a compromise version , Pictured : choose 3.2, Because this version bug Not too much , And if something goes wrong, you can find many solutions online , If elected 2.2, Although already very mature , But the function doesn't 3.2 More .
  2. download django
    Enter the virtual environment under the project directory , Input :pip install django==3.2, If the speed is too slow , Just press the Ctrl+C Finish the process first , Input again pip install django==3.2 -i https://pypi.tuna.tsinghua.edu.cn/simple.
    Wait for a moment and the download succeeds !
    here pip freeze You can see

    More than a Django modular
  3. establish django project
    Enter the virtual environment under the project directory , Input django-admin startproject ( Project name )
    At this time, there are more items under our project folder

    manage.py Execute documents for the project , He can carry out the project
  4. New project application
    Enter the virtual environment under the project directory , Then go to the next folder :cd one, Why? ?
    You can see , I just had manage.py Is in
    In this directory , Want to execute manage.py You must enter this directory first
    Then input :python manage.py startapp App( I want to create a new one next time App You can also use this statement )
    This time, , Our project folder has more items named :App Folder , There will be these things in him

    At this time , We type in python manage.py runserver You can see the following

    Then find a browser and type 127.0.0.1:8000

    ha-ha ! Create success !
    If the last sentence is the following ↓

    Please turn off the cool dog music , Or input python manage.py runserver 9000
    When you want to turn it off Ctrl+C

Successfully created django project , We might think , Where do I write my code ?
Of course not at the terminal , It's too hard . We use it pycharm,pycharm The powerful prompt function can bring great convenience to our development .
You can download it from the official website , Community Edition is fine , But it's best to have a professional version , In this way, the above steps of more than 3000 words can be directly omitted , It's just pycharm The activation of the professional version is a little troublesome , Many students may have wanted to give up when they activated ! Because it is more metaphysical , And the community version can solve the problem , So I won't go into details here .

adopt pycharm Open project file

  1. open pycharm
  2. Click on File–>open or
  3. Find the newly created project file , Click on manage.py Folder on top of

    Wait for the loading to complete , We need to configure the virtual environment we just created to pycharm in , tell pycharm, We use this virtual environment
    Now open Settings(File–>Settings)

    Click in and find the triangle in the box above showall

    Did you find the virtual environment we just created , Click the plus sign on the right side of the window

    choice Existing environment, spot …
    Then find the location of the virtual environment , Mine is here , For reference only

    choice python, Click on OK、OK、OK…
    Now our django Project documents can be found in pycharm It has been used. !

Let's talk about the method of creating project engineering in professional edition
First of all :

second :

Third :


Finally, click create That is, the creation is successful !


By the way : The professional edition is created by default every time django It's the latest version !


  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式師世界 All Rights Reserved