Dav*_*ito 1 python django django-rest-framework
遵循有关模块化我的 django 代码的django 教程,我已经能够分离出一些应用程序。我为这些应用程序制作了包,我们成功地在多个项目中使用了它们。
我们的样板项目目录看起来有点像这样(非常像教程中的):
boilerplate/
boilerplate/boilerplate/settings.py
boilerplate/boilerplate/....
boilerplate/user_profile/admin.py, models.py, etc.
Run Code Online (Sandbox Code Playgroud)
理想情况下,我们只需pip install在user_profile应用程序,包括在项目的设置,我们是好去。
但是,无论何时我必须更新应用程序user_profile,我都必须在项目中运行它并进行开发。
是否有我可以遵循的可能的工作流程,以便我可以粗略地仅在user_profile应用程序/模块上进行开发,而无需设置整个项目。我知道设置项目的痛点只有一两行,但在我的情况下,我们使用自定义数据库设置(使用 MongoDB)并且快速设置这些内容意味着我必须更改我的机器(或环境)上的设置) 每次我必须在这个项目上工作。
小智 7
一个简单的最小示例是使用以下代码创建文件 manage.py
import sys
urlpatterns = []
# since django will search for ROOT_URLCONF from settings,
# and we have given this same file as ROOT_URLCONF on settings, see below
if __name__ == "__main__":
import django
from django.conf import settings
from django.core.management import execute_from_command_line
settings.configure(
SECRET_KEY='YOURSECRETKEY',
DEBUG=True,
ROOT_URLCONF='manage',
INSTALLED_APPS=[
# list of your apps
]
)
# Note: you may need to configure database also
django.setup() # setup django after configuring settings
execute_from_command_line(sys.argv) # let this handle commands as always
Run Code Online (Sandbox Code Playgroud)
根据需要配置设置,只需运行 - python manage.py runserver作为示例
| 归档时间: |
|
| 查看次数: |
451 次 |
| 最近记录: |