是否有一些全局变量用于django模板中的gettin'语言代码或至少通过视图传递它?例如:{{ LANG }}应该生成"en"例如..当人们使用时我真的不舒服request.LANGUAGE_CODE.
详细解释将被赞赏=)
我需要在视图中使用SHORT_DATETIME_FORMAT.
def manage_list(request):
user = User.objects.filter().order_by('date_joined')
usrs = []
for usr in user:
usrs.append({
_('First name'): usr.first_name,
_('Last name'): usr.last_name,
_('Email'): usr.email,
_('Active'): usr.is_active,
_('Superuser'): usr.is_superuser,
_('Staff'): usr.is_staff,
_('Joined date'): usr.date_joined.strftime(SHORT_DATETIME_FORMAT),
})
data = simplejson.dumps(usrs, indent=4)
return HttpResponse(data, mimetype='application/json')
Run Code Online (Sandbox Code Playgroud)
我认为usr.date_joined有一种"日期字段".我想根据django语言环境格式化这些数据.所以这个字符串可能应该有所帮 我知道有一个模板过滤器可以做到这一点,但是我想在视图中格式化usr.date_joined - 保存django选择的语言环境.
如果还有其他方法可以做到这一点,请提供示例.最后我想根据django locale显示一个格式化的日期,它只显示日期和时间,我认为这个常量应该按照名称所说的去做.
当使用vagrant和chef作为供应者时,我收到了这个警告:
[web] Chef 11.12.2 Omnibus package is already installed.
[web] Running provisioner: chef_solo...
Generating chef JSON and uploading...
Running chef-solo...
stdin: is not a tty
[2014-04-10T14:48:46+00:00] INFO: Forking chef instance to converge...
[2014-04-10T14:48:46+00:00] WARN:
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
SSL validation of HTTPS requests is …Run Code Online (Sandbox Code Playgroud) 我真的需要在git中使用这个命令
hg addremove
Run Code Online (Sandbox Code Playgroud)
所以现在看一下场景,看看mercurial会如何拯救我:
我在这里有一些dir/htdocs/static/static.我不小心将文件移动到错误的位置(使用git-mv).无论如何......现在我手动移动了一些文件夹:
mv static static2
mv static2/static ./
Run Code Online (Sandbox Code Playgroud)
也许我已经在这里更改了一些文件......现在一切都很棒......所以现在git不知道发生了什么?他如何能够跟踪文件的移动而不用像mercurial那样通知addremove.
例如,现在我可以做mercurial:
hg addremove --similarity 80%
Run Code Online (Sandbox Code Playgroud)
就是这样 - 通过识别文件内容来追踪文件被移动的地方,并保存了我的文件历史记录.
这里的一个小伙子有一些技巧:
git add .
git ls-files --deleted | xargs git rm
Run Code Online (Sandbox Code Playgroud)
但那就像当时的CVS一样.你删除文件,你添加文件.怎么样保存文件的历史?
我终于设法让它工作,所以当你推动分支工作将启动,但我一直在等待它启动大约3分钟,然后我有错误,我需要修复,然后再次提交,然后再等一等.我怎样才能直接对那个公共参赛者进行测试并在bash中测试.gitlab-ci.yml"script"部分?
我曾试图在这里问过一次问题,但没有人理解我想问的问题.所以我在PHP中找到了一些例子.
// $_POST = array('address' => '123', 'name' => 'John Doe');
extract($_POST);
echo $address;
echo $name
Run Code Online (Sandbox Code Playgroud)
在PYTHON中是否有类似extract()的函数?????
字典也一样:
mydict = {'raw':'data', 'code': 500}
// some magic to extract raw and code as vars
print raw
Run Code Online (Sandbox Code Playgroud)
ps为什么我要这样做:当你在类方法时,当string是self.data ['raw'] ['code']时,很难在join()和format()中使用字符串进行6次操作.假设它在这里的字典中是dict)
主要目标是自动添加所有puppet模块,以便可以使用一个命令启动所有dev-env和prod-env.如何通过木偶清单安装木偶模块?
我安装了这两个应用程序后出现此错误:https://github.com/dyve/django-bootstrap3和https://github.com/django-admin-bootstrapped/django-admin-bootstrapped
django@apgavo:~/apgavo$ python manage.py collectstatic
Traceback (most recent call last):
File "manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "/usr/local/lib/python2.7/dist-packages/django/core/management/__init__.py", line 385, in execute_from_command_line
utility.execute()
File "/usr/local/lib/python2.7/dist-packages/django/core/management/__init__.py", line 354, in execute
django.setup()
File "/usr/local/lib/python2.7/dist-packages/django/__init__.py", line 21, in setup
apps.populate(settings.INSTALLED_APPS)
File "/usr/local/lib/python2.7/dist-packages/django/apps/registry.py", line 89, in populate
"duplicates: %s" % app_config.label)
django.core.exceptions.ImproperlyConfigured: Application labels aren't unique, duplicates: bootstrap3
Run Code Online (Sandbox Code Playgroud)
settings.py:
INSTALLED_APPS = (
'django_admin_bootstrapped.bootstrap3',
'django_admin_bootstrapped',
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'django_extensions',
'bootstrap3',
)
Run Code Online (Sandbox Code Playgroud)
无论如何还有解决这个问题的方法吗?或者这应该作为一个问题提交给其中一个项目?
用例实际上是自动执行此操作ansible.我想只在数据库完全为空(内部没有表)时导入数据库转储.当然总有办法执行sql语句,但这是最后的手段,我相信应该有更优雅的解决方案.
pg_restore 就我看来,手册不提供此选项.
以下是我计划用ansible执行此操作的方法:
- name: db_restore | Receive latest DB backup
shell: s3cmd --skip-existing get `s3cmd ls s3://{{ aws_bucket }}/ | grep sentry | tail -1 | awk '{print $4}'` sql.latest.tgz
args:
chdir: /root/
creates: sql.latest.tgz
- name: db_restore | Check if file exists
stat: path=/root/sql.latest.tgz
register: sql_latest
- name: db_restore | Restore latest DB backup if backup file found
shell: PGPASSWORD={{ dbpassword }} tar -xzOf /root/sentry*.tgz db.sql | psql -U{{ dbuser }} -h{{ pgsql_server …Run Code Online (Sandbox Code Playgroud)