将字符串替换为空字符串的特殊字符(Replace string with special characters for empty string)
说我的字符串看起来像这样......
var find = '&roadmap=1';
我想将我的网址中该字符串的所有实例替换为
''
。
url.replace(find, '');
好像扔了:uncaught typeerror: url.replace is not a function
我认为这是因为查找字符串本身中的特殊字符。 那么如何从我的网址中删除
&roadmap=1
所有实例?Say my string looks like this...
var find = '&roadmap=1';
I want to replace all instances of that string in my url to
''
.
url.replace(find, '');
seems to throw :uncaught typeerror: url.replace is not a function
I assume it's because of the special characters within the find string itself. So how can I remove all instances of
&roadmap=1
from my url?
原文:
最满意答案
虽然这是一种常见的方法,但这不是一个好方法。 我过去曾使用过这种配置,因此放弃了它。 当您有多个开发人员一起工作或部署到多个环境(即分段和生产)时,问题就出现了。 您可以选择其中之一
- make
settings.py
生产设置。 然后,每个开发人员必须覆盖设置以设置其本地环境(数据库设置,DEBUG=True
,添加debug_toolbar
等)。 由于这不是源代码控制,它是重复工作,并导致“它在我的机器上工作”的各种问题。- make
settings.py
开发设置。 现在,您在local_settings.py
拥有有意义的生产配置部分,这些部分不在源代码管理中 。 这使部署变得混乱。 显然,您不希望将敏感信息放在源代码管理中。添加暂存环境只会让情况变得更糟。 我更喜欢SplitSettings wiki中描述的简单包环境组织 。
While this is a common approach it is not a good approach. I have used this type of configuration in the past and since abandoned it. The problem comes when you have multiple developers working together or when you are deploying to multiple environments (i.e. staging and production). You have the choice of either
- Make
settings.py
the production settings. Then each developer must override settings to setup their local environment (DB settings,DEBUG=True
, addingdebug_toolbar
, etc). Since this is not in source control it is repeated work and leads to "it works on my machine" kinds of problems.- Make
settings.py
the development settings. Now you have meaningful pieces of your production configuration inlocal_settings.py
which is not in source control. This makes deployment messy. Obviously you don't want to put sensitive information in the source control.Adding a staging environment just makes this worse. I much prefer the Simple Package Organization for Environments described in the SplitSettings wiki.
相关问答
更多-
如果我检查settings.DEBUG,Django不提供媒体文件(Django not serving media files if I check for settings.DEBUG)[2022-01-25]
使用 if settings.DEBUG: urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT) (在'+'之后注意'=' - 在您的版本中添加static()模式但不将结果分配给urlpatterns变量) Use if settings.DEBUG: urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDI ... -
代替 from myproj import settings 做 from django.conf import settings 这就是DEBUG的工作原理: https://docs.djangoproject.com/en/dev/topics/settings/#using-settings-in-python-code Instead of from myproj import settings do from django.conf import settings That's why ...
-
Jarret是对的。 最佳案例场景:如果您在重新启动服务器后运行一个非常简单的测试,这将起作用。 几乎其他任何事情都会打破它。 如果你只是使用MEDIA_ *作为常量,我建议使用其他常量。 如果您确实在使用它们进行文件字段的默认上传设置,则听起来您的项目将要求您指定路径。 这应该不会太难。 您需要克服的问题有两个问题,即您目前的方案无法解决: 每次发出请求时都动态设置变量 避免不良的竞争条件 1最好通过自定义MiddleWare完成,可能使用process_request方法。 但是,你想避免的是, set ...
-
在一个文件夹中创建我们自己的config.py文件 settings = {} settings['server'] = '172.16.150.106:1433' settings['user'] = 'pyadmin' settings['password'] = 'admin' settings['db'] = 'SQLSERV_2005' 打开shell(ipython) In [1]: from config import settings In [2]: print settings {' ...
-
多个设置文件(Multiple settings files)[2023-09-26]
Django的SECRET_KEY有许多围绕加密签名的用法。 例如,这就是如何保护cookie或Django如何确保隐藏的表单字段不被篡改。 manage.py runserver是你不应该在生产中使用的开发服务器:你可能在那里使用WSGI:修改manage.py将不会做任何事情。 Django's SECRET_KEY has many usages revolving around cryptographic signing. For example, this is how cookies are p ... -
您可以为每个项目单独将每个设置文件传递给guincorn。 我建议调查supervisord来管理你的guincorn进程,这样你就可以使用不同的设置为每个项目保持一个运行。 您可以设置配置文件,如 [program:project1] command=/var/www/project1/manage.py run_gunicorn --settings=project1.settings.production directory=/var/www/project1/ environment=PATH="/ ...
-
在Django中修改设置(Modifing settings in Django)[2022-03-25]
如果可以帮助,请不要修改manage.py。 而是传递--settings参数来选择备用设置模块。 设置一个shell脚本或别名将使它更容易使用它。 Don't modify manage.py if you can help it. Instead pass it the --settings argument to choose an alternate settings module. Setting up a shell script or alias will make it easier to ... -
我会尽量做到尽可能简洁。 你真的需要阅读文档 (甚至是这个 ),你阅读得越多越好,因为你不会在这里得到关于如何在apache上为django站点提供详细和示例的明确答案。 在那里你的项目是由你自己决定的,换句话说它不应该放在/var/www/ 为了一次持有2+ django项目,请尝试使用单独的wsgi守护进程。 看看 。 这将不允许不同的应用程序互相干扰。 然而,我建议在/etc/apache2/sites-available文件(通常每个文件一个)中为你的项目设置config(作为虚拟主机)。 我强烈建 ...
-
解决方案是使用环境变量。 在celery.py 代替 os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'proj.settings') 使用 os.environ.setdefault('DJANGO_SETTINGS_MODULE', '{0}'.format(get_env_setting('DJANGO_SETTINGS_MODULE'))) 将get_env_setting定义为: from os import environ from djang ...
-
虽然这是一种常见的方法,但这不是一个好方法。 我过去曾使用过这种配置,因此放弃了它。 当您有多个开发人员一起工作或部署到多个环境(即分段和生产)时,问题就出现了。 您可以选择其中之一 make settings.py生产设置。 然后,每个开发人员必须覆盖设置以设置其本地环境(数据库设置, DEBUG=True ,添加debug_toolbar等)。 由于这不是源代码控制,它是重复工作,并导致“它在我的机器上工作”的各种问题。 make settings.py开发设置。 现在,您在local_settings ...