Menu
×
   ❮   
HTML CSS JAVASCRIPT SQL PYTHON JAVA PHP HOW TO W3.CSS C C++ C# BOOTSTRAP REACT MYSQL JQUERY EXCEL XML DJANGO NUMPY PANDAS NODEJS R TYPESCRIPT ANGULAR GIT POSTGRESQL MONGODB ASP AI GO KOTLIN SASS VUE DSA GEN AI SCIPY AWS CYBERSECURITY DATA SCIENCE
     ❯   

部署 Django - 创建需求文件


锁定依赖项

创建 Django 应用程序时,项目依赖于一些 Python 包。

Django 本身就是一个 Python 包,我们必须确保部署项目的服务器也安装了 Django 包,以及项目所需的所有其他包。

幸运的是,也有一个命令可以做到这一点,只需在命令视图中运行此命令即可

py -m pip freeze > requirements.txt

上述命令的结果是在项目中创建了一个名为 requirements.txt 的文件

my_tennis_club
    members/
    my_tennis_club/
    mystaticfiles/
    productionfiles/
    db.sqlite3
    manage.py
    requirements.txt

该文件包含此项目依赖的所有包:内容如下

my_tennis_club/requirements.txt:

asgiref==3.5.2
Django==4.1.4
psycopg2-binary==2.9.5
sqlparse==0.4.3
tzdata==2022.7
whitenoise==6.2.0

注意:您可以自己创建此文件,并手动插入包,只需确保获取项目依赖的所有包,并且必须将文件命名为 requirements.txt

现在,托管提供商知道在部署项目时要安装哪些包。

但 Elastic Beanstalk 需要更多信息,请转到下一章创建“EB”配置文件。


×

Contact Sales

If you want to use W3Schools services as an educational institution, team or enterprise, send us an e-mail:
[email protected]

Report Error

If you want to report an error, or if you want to make a suggestion, send us an e-mail:
[email protected]

W3Schools is optimized for learning and training. Examples might be simplified to improve reading and learning. Tutorials, references, and examples are constantly reviewed to avoid errors, but we cannot warrant full correctness of all content. While using W3Schools, you agree to have read and accepted our terms of use, cookie and privacy policy.

Copyright 1999-2024 by Refsnes Data. All Rights Reserved. W3Schools is Powered by W3.CSS.