- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我已经编写了一个 Django 应用程序,现在我希望能够轻松地在多个服务器上部署。
基本安装是:
settings.py
中的 INSTALLED_APPS
./manage.pycollectstatic
这个特定的应用程序不需要使用数据库,但如果需要,我会使用 South 并运行 ./manage.py migrate
,但那是另一个故事了。
我遇到问题的部分是#2。我不想每次都手动编辑这个文件。更新最简单/最可靠的方法是什么?
我想我可以使用 inspect
模块来查找变量,然后以某种方式附加它,但我没有任何运气。 inspect.getsourcelines
找不到变量。
最佳答案
您可以使用 bash 修改 settings.py。
#set $SETTINGS_FILE variable to full path of the your django project settings.py file
SETTINGS_FILE="/path/to/your/django/project/settings.py"
# checks that app $1 is in the django project settings file
is_app_in_django_settings() {
# checking that django project settings file exists
if [ ! -f $SETTINGS_FILE ]; then
echo "Error: The django project settings file '$SETTINGS_FILE' does not exist"
exit 1
fi
cat $SETTINGS_FILE | grep -Pzo "INSTALLED_APPS\s?=\s?\[[\s\w\.,']*$1[\s\w\.,']*\]\n?" > /dev/null 2>&1
# now $?=0 if app is in settings file
# $? not 0 otherwise
}
# adds app $1 to the django project settings
add_app2django_settings() {
is_app_in_django_settings $1
if [ $? -ne 0 ]; then
echo "Info. The app '$1' is not in the django project settings file '$SETTINGS_FILE'. Adding."
sed -i -e '1h;2,$H;$!d;g' -re "s/(INSTALLED_APPS\s?=\s?\[[\n '._a-zA-Z,]*)/\1 '$1',\n/g" $SETTINGS_FILE
# checking that app $1 successfully added to django project settings file
is_app_in_django_settings $1
if [ $? -ne 0 ]; then
echo "Error. Could not add the app '$1' to the django project settings file '$SETTINGS_FILE'. Add it manually, then run this script again."
exit 1
else
echo "Info. The app '$1' was successfully added to the django settings file '$SETTINGS_FILE'."
fi
else
echo "Info. The app '$1' is already in the django project settings file '$SETTINGS_FILE'"
fi
}
用途:
add_app2django_settings "my_app"
关于python - Django 应用程序安装脚本 - 如何将应用程序添加到 INSTALLED_APPS 设置?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7323243/
我正在尝试创建我的 Django 项目/网站的“投票”部分,教程 (https://docs.djangoproject.com/en/1.8/intro/tutorial01/) 说在我们“激活”模
我正在开发一个应用程序,它需要安装另一个应用程序。我可以将它添加到我的 setup.py 中,它也会安装其他应用程序。 安装我的应用程序后,我需要将它添加到 INSTALLED_APPS,但我也需要添
INSTALLED_APPS 中应用的顺序重要吗?我问它是因为我有 settings 文件夹,其中包含两个 settings 文件:base.py 和 production.py 我将我所有的设置放在
我有一个包含许多应用程序的项目。这些应用程序转换为为最终用户执行不同功能的模块。 现在项目的每个部署都可能启用或禁用某些应用程序。 我想要实现的是一个链接导航列表,它只显示 INSTALLED_APP
在我的 Django 项目下有一些应用程序,它们都有单元测试。我现在正在工作的其中一个应该只包含在开发/阶段环境中,所以我使用环境变量启用它。 当这个变量存在时,它被添加到 INSTALLED_APP
这个问题已经有答案了: Django 1.9 can not find newapp (2 个回答) 已关闭 6 年前。 我有一个规范形式的 django 项目: .├── app1/├── app2
Django 文档 says : the final dotted part of the path to the module defined in INSTALLED_APPS must be u
我有一个正在构建的 Django 应用程序,我们将其称为 foo。 由于 Foo 的构建方式,它需要许多第三方 django 应用程序才能运行。例如,要运行 Foo,安装应用程序可能如下所示: INS
在 Django 中导入模型模块时出现以下错误。 /Users/markcollier/Documents/Adapt/Taboo/TabooAPI/env/lib/python2.7/site-pa
当我使用库“ckeditor”运行服务器时,我在 manage.py 文件中遇到了这个错误(我在使用 tinymce 时也遇到了同样的错误): Traceback (most recent call
我正在尝试将现有的 django 1.4 项目移植到 django 1.7 这是我将项目移植到 django 1.7 之前的树结构 Project - MainApp - manage.py
我目前只是将应用程序添加到 INSTALLED_APPS 以便能够使用来自该应用程序的模板,但也有 TEMPLATE_DIRS 设置。我什么时候更喜欢 TEMPLATE_DIRS 而不是 INSTAL
这实际上是做什么的?我最近将我的项目从 1 个应用程序扩展到 6 个不同的应用程序,并且忘记更新我的设置文件的 INSTALLED_APPS 部分。即使我没有列出新应用程序,一切仍然有效。这应该发生吗
网站上的教程创建了一个名为 polls 的应用程序。它使用的是 django 1.9,所以在 INSTALLED_APPS 中是: polls.apps.PollsConfig 我正在看一个教程,他命
它只是一个示例应用程序, 应用名称:wiki #models.py from django.db import models class Page(models.Model): name = mode
我有一个应用程序(django-compressor),我只想在我的本地机器上而不是服务器上运行。我知道 try: from local_settings import * except Im
我已经编写了一个 Django 应用程序,现在我希望能够轻松地在多个服务器上部署。 基本安装是: 将应用程序文件夹复制到 Django 项目文件夹中 将其添加到 settings.py 中的 INST
我想在我的 Django 项目中使用 django-moderation。我已经使用 pip3 下载了该应用程序,问题是当我将应用程序添加到 INSTALLED_APPS 时,出现以下异常。您能告诉我
Django 教程使用 installed_apps 中的列表说明如下。但默认是一个元组,其他消息来源也说 Django 在这种情况下更喜欢元组而不是列表。 我的问题是:如果我按照教程中的说明使用列表
情况是这样的。我有一个带有两个已安装应用程序的 Django 项目。如果这两个应用程序彼此独立安装,它们似乎可以正常运行。 但是,如果我在 settings.INSTALLED_APPS 中列出这两个
我是一名优秀的程序员,十分优秀!