设置 Django 项目的更简单方法?
我刚刚开始使用 Django,我发现我正在做的一件事就是启动很多新项目。我发现这个过程每次都非常乏味,即使使用 manage.py startproject *
我也会不断更改 settings.py 中的设置,例如 media_root 和模板路径。简单介绍一下背景,我来自 PHP 和 CodeIgniter。我从未使用过库存 CI 目录。我对其进行了修改以满足我对新项目的需求。当我需要一个新项目时,我只需复制该目录即可。 manage.py
似乎是动态生成文件的,所以这种方法似乎不太可能。还有其他人对此有什么建议吗?
I've just started using Django and one thing I find that I'm doing is starting a lot of new projects. I'm finding this process to be pretty tedious every time, even using manage.py startproject *
I'm constantly changing settings in settings.py like media_root and template paths. Just a little background, I come from PHP and CodeIgniter. I never used a stock CI directory. I modified it to meet my needs for a new project. When I needed a new project, I would just copy that directory. manage.py
seems to generate the files on the fly so this approach doesn't seem that possible. Does anyone else have any advice on this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
Lincoln Loop 有一些最佳实践,他们建议从不同的文件导入设置。 http://lincolnloop.com/django-best-practices/projects/modules /settings.html
另外,请检查 pip 要求,您也许可以使用它从外部源(如 git 存储库)安装设置模块。
Lincoln loop has some best practices, they suggest importing settings from a different file. http://lincolnloop.com/django-best-practices/projects/modules/settings.html
Also checkout pip requirements, you might be able to use this to install the settings module from an external source like a git repo.
我正在使用 Paver 来自动化我的 Django 项目设置。
我有一个 Bitbucket 存储库,其中包含我自己的引导程序设置。最终我会让这个通用,但现在它可能会给你一些示例代码
I'm using Paver to automate my Django project setup.
I have a Bitbucket repository with my own bootstrap setup. Eventually I'll make this generic, but for now it might give you some example code
听起来你经常开始新项目。我想那是因为你正在学习。当然,如果有一个自定义
settings.py
可以在您生成学习项目时节省一些输入,请创建它并使用它。您可以将模板设置为整个项目目录,但由于您不太可能在settings.py
之外拥有大量项目级样板,因此只需关注该文件即可。设置文件是项目的本质。Django 开发都是关于应用程序的。随着您了解更多,应用程序将开始成为您的焦点。我的建议是不要投入太多精力来为项目创建建立高效的装配线。
另外,请学习并使用版本控制。为了获得奖励积分,还可以学习和使用 virtualenv :)
Sounds like you're starting new projects very often. I assume that's because you're learning. Sure, if there's a custom
settings.py
that will save you some typing as you generate your learning projects, create it and use it. You could make your template the whole project directory, but since you're unlikely to have a lot of project-level boilerplate outside ofsettings.py
, just focus on that one file. The settings file is the essence of the project.Django development is all about apps. As you learn more, apps will start to become your focus. My advice would be not to pour too much energy into making an efficient assembly line for project creation.
Also, please learn and use use version control. For bonus points, also learn and use virtualenv :)