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

Django installed in pipenv

編輯:Python

install  Pipenv

Pipenv  It is a tool for production flow , Designed to pack the best in the world ( bundler, composer, npm, cargo, yarn, etc. ) Into the  Python  The world . It will  Pipfile、pip  and  virtualenv  Integrate into one command .
We can use  pip  Command to install   pip3 install --user pipenv$ pip3 install --user pipenv
Collecting pipenv
 Downloading pipenv-2022.5.2-py2.py3-none-any.whl (3.9 MB)
 |████████████████████████████████| 3.9 MB 634 kB/s 
Collecting virtualenv-clone>=0.2.5
 Downloading virtualenv_clone-0.5.7-py3-none-any.whl (6.6 kB)
Requirement already satisfied: certifi in /usr/lib/python3/dist-packages (from pipenv) (2019.11.28)
Collecting pip>=22.0.4
 Downloading pip-22.1.2-py3-none-any.whl (2.1 MB)
 |████████████████████████████████| 2.1 MB 2.3 MB/s 
Requirement already satisfied: setuptools>=36.2.1 in /usr/lib/python3/dist-packages (from pipenv) (45.2.0)
Requirement already satisfied: virtualenv in /usr/lib/python3/dist-packages (from pipenv) (20.0.17)
Installing collected packages: virtualenv-clone, pip, pipenv
Successfully installed pip-22.1.2 pipenv-2022.5.2 virtualenv-clone-0.5.7

Why is it recommended to use  pipenv, Because it automatically creates and manages virtual environments for your projects  virtualenv, And before you install / Uninstall the package from your  Pipfile  Add / Delete package . It also generates very important  Pipfile.lock, Used to generate deterministic builds .

install  Django


Create a project folder  mytodo :$ mkdir mytodo 
$ cd mytodo 

Django  It's an advanced  Python Web  frame , It encourages rapid development and simplicity 、 Practical design . It's built by experienced developers , It's solved  Web  Most of the trouble with development , So you can focus on writing applications , Without reinventing the wheel . It's free and open source .
Use  pipenv install django  Install your in a virtual environment  django  frame :$ sudo pipenv install django
Creating a virtualenv for this project...
Pipfile: /home/wade/PythonProject/mytodo/Pipfile
Using /usr/bin/python3 (3.8.10) to create virtualenv...
⠼ Creating virtual environment...created virtual environment CPython3.8.10.final.0-64 in 439ms
 creator CPython3Posix(dest=/root/.local/share/virtualenvs/mytodo--AJz7sim, clear=False, global=False)
 seeder FromAppData(download=False, pip=latest, setuptools=latest, wheel=latest, pkg_resources=latest, via=copy, app_data_dir=/root/.local/share/virtualenv/seed-app-data/v1.0.1.debian.1)
 activators BashActivator,CShellActivator,FishActivator,PowerShellActivator,PythonActivator,XonshActivator

 Successfully created virtual environment! 
Virtualenv location: /root/.local/share/virtualenvs/mytodo--AJz7sim
Creating a Pipfile for this project...
Installing django...
Adding django to Pipfile's [packages]...
 Installation Succeeded 
Pipfile.lock not found, creating...
Locking [dev-packages] dependencies...
Locking [packages] dependencies...
Building requirements...
Resolving dependencies...
 Success! 
Updated Pipfile.lock (a6086c)!
Installing dependencies from Pipfile.lock (a6086c)...
  ▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉ 0/0 — 00:00:00
To activate this project's virtualenv, run pipenv shell.
Alternatively, run a command inside the virtualenv with pipenv run.

Verify the installation

  • Use  pipenv run python3  Activate  python  Environmental Science
  • Import  django  package : import django
  • Print  django  edition :print(django.get_version())

verification  Django  Installation successful :$ sudo pipenv run python3
Python 3.8.10 (default, Mar 15 2022, 12:22:08) 
[GCC 9.4.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import django
>>> print(django.get_version())
4.0.5
>>> 

start-up  django  Program


Use  pipenv run python3 manage.py runserver  To start the default  django  Program :$ sudo pipenv run python3 manage.py runserver
Watching for file changes with StatReloader
Performing system checks...

System check identified no issues (0 silenced).

You have 18 unapplied migration(s). Your project may not work properly until you apply the migrations for app(s): admin, auth, contenttypes, sessions.
Run 'python manage.py migrate' to apply them.
June 07, 2022 - 07:54:34
Django version 4.0.5, using settings 'todobackend.settings'
Starting development server at http://127.0.0.1:8000/
Quit the server with CONTROL-C.
[07/Jun/2022 07:55:05] "GET / HTTP/1.1" 200 10697
[07/Jun/2022 07:55:07] "GET /static/admin/css/fonts.css HTTP/1.1" 200 423
[07/Jun/2022 07:55:16] "GET /static/admin/fonts/Roboto-Bold-webfont.woff HTTP/1.1" 200 86184
[07/Jun/2022 07:55:16] "GET /static/admin/fonts/Roboto-Regular-webfont.woff HTTP/1.1" 200 85876
[07/Jun/2022 07:55:16] "GET /static/admin/fonts/Roboto-Light-webfont.woff HTTP/1.1" 200 85692
Not Found: /favicon.ico
[07/Jun/2022 07:55:18] "GET /favicon.ico HTTP/1.1" 404 2115

Access the local server address  http://127.0.0.1:8000/, You can see the following interface ,django  Program started successfully :

summary

This article first introduces a very useful  Python  Project environment and dependency management tools  pipenv, Then install the local environment  pipenv , adopt  pipenv  Conduct  django  Project Management , Finally, it introduces  django  Install a virtual environment to start one  django  Program .
Reference link :
  • pipenv:https://pypi.org/project/pipenv/
  • Writing your first Django app

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