Python中文
首页
教程
问答
标签
搜索
登录
注册
Django rest框架中的日期国际化?
回答此问题可获得
20
贡献值,回答如果被采纳可获得
50
分。
<p>我试图翻译API中的日期(<strong><a href="http://www.django-rest-framework.org/" rel="nofollow noreferrer" title="Django rest framework">Django rest framework</a></strong>), 现在,国际化和本地化在其他方面都起作用了,但我还没赶上。在</p> <p>这里只有英语和法语,而且我已经重新启动了几次服务器,但无法在<em>FR</em>中获取日期,如您所见,我使用了<a href="http://django-rosetta.readthedocs.io/en/latest/" rel="nofollow noreferrer" title="Rosetta">Rosetta</a><a href="https://i.stack.imgur.com/L5kUZ.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/L5kUZ.png" alt="enter image description here"/></a></p> <p><strong>示例代码:</strong></p> <pre><code>@staticmethod def get_start_date(obj): return obj.start_date.strftime("%d %B, %Y") </code></pre> <p>当lang code<strong>en</strong> O/P是:</p> <p><strong>开始日期:“2016年1月1日”</strong></p> <p>但当lang代码<strong>fr</strong>预期结果时:</p> <p><strong>开始日期:“2016年1月1日”</strong></p> <p>它仍然在用英语显示</p> <p><em>设置.py</em> 我已经成功地为你的信息添加了基本设置</p> ^{pr2}$ <p>提前谢谢</p>
0 条评论
分类:
Python问答
请先
登录
后评论
默认排序
时间排序
1 个回答
匿名
1天前
擅长:python、mysql、java
<p>这也是黑客,但有帮助。在Rest视图中添加:</p> <pre><code>import locale locale.setlocale(locale.LC_TIME, "ru_RU.utf-8") </code></pre>
请先
登录
后评论
针对此问题:
更多的回答
关注
89
关注
收藏
1
收藏,
216
浏览
网友 提问于 2天前
相关Python问题
VirtualEnvRapper错误:路径python2(来自python=python2)不存在
1 回答
virtualenvs上的pyinstaller,没有名为导入错误的模块
10 回答
virtualenvs是否可以退回到用户包而不是系统包?
4 回答
virtualenvwrapper CentOS7
2 回答
virtualenvwrapper IOError:[Errno 13]权限被拒绝
8 回答
virtualenvwrapper mkproject和shell在windows中的启动问题?
6 回答
virtualenvwrapper mkvirtualenv不工作但没有错误
6 回答
Virtualenvwrapper python bash
5 回答
virtualenvwrapper:“workon”何时更改到项目目录?
5 回答
virtualenvwrapper:mkvirtualenv可以工作,但是rmvirtualenv返回bash:没有这样的文件或目录
7 回答
virtualenvwrapper:virtualenv信息存储在哪里?
10 回答
virtualenvwrapper:命令“python设置.pyegg_info“失败,错误代码为1
7 回答
virtualenvwrapper:如何将mkvirtualenv的默认Python版本/路径更改为ins
2 回答
Virtualenvwrapper:模块“pkg_resources”没有属性“iter_entry_points”
7 回答
Virtualenvwrapper:没有名为virtualenvwrapp的模块
4 回答
Virtualenvwrapper.bash_profi的正确设置
9 回答
Virtualenvwrapper.hook:权限被拒绝
2 回答
virtualenvwrapper.sh:fork:资源暂时不可用Python/Djang
2 回答
Virtualenvwrapper.shlssitepackages命令不工作
1 回答
Virtualenvwrapper.sh函数在bash sh中不可用
9 回答