1
matrix1010 2018-07-21 22:55:54 +08:00 via Android
因为是 Date, 只有年月日, 没有小时
|
2
chengxiao 2018-07-21 23:15:51 +08:00
看看 model 里定义的时间类型错了
|
3
Zzdex 2018-07-21 23:35:28 +08:00
看看你的 `date_added`是`DatetimeField` 还是 `Datefield`
|
4
inoki 2018-07-22 17:59:18 +08:00 via Android
见#3
models.DatetimeField <=> models.DateField |
5
getlost OP @matrix1010 @chengxiao 谢谢各位老哥
|
6
getlost OP @Zzdex @inoki 两位老哥思路是对的,但是我将 models.DateField 改为 models.DateTimeField 出现了新的错误,下面是报错
Internal Server Error: /topics/1/ Traceback (most recent call last): File "d:\t_django\ll_env\lib\site-packages\django\core\handlers\exception.py", line 35, in inner response = get_response(request) File "d:\t_django\ll_env\lib\site-packages\django\core\handlers\base.py", line 128, in _get_response response = self.process_exception_by_middleware(e, request) File "d:\t_django\ll_env\lib\site-packages\django\core\handlers\base.py", line 126, in _get_response response = wrapped_callback(request, *callback_args, **callback_kwargs) File "d:\t_django\t_djangos\views.py", line 20, in topic topic = Topic.objects.get(id=topic_id) File "d:\t_django\ll_env\lib\site-packages\django\db\models\manager.py", line 82, in manager_method return getattr(self.get_queryset(), name)(*args, **kwargs) File "d:\t_django\ll_env\lib\site-packages\django\db\models\query.py", line 397, in get num = len(clone) File "d:\t_django\ll_env\lib\site-packages\django\db\models\query.py", line 254, in __len__ self._fetch_all() File "d:\t_django\ll_env\lib\site-packages\django\db\models\query.py", line 1179, in _fetch_all self._result_cache = list(self._iterable_class(self)) File "d:\t_django\ll_env\lib\site-packages\django\db\models\query.py", line 62, in __iter__ for row in compiler.results_iter(results): File "d:\t_django\ll_env\lib\site-packages\django\db\models\sql\compiler.py", line 1011, in apply_converters value = converter(value, expression, connection) File "d:\t_django\ll_env\lib\site-packages\django\db\backends\sqlite3\operations.py", line 222, in convert_datetimefield_value value = parse_datetime(value) File "d:\t_django\ll_env\lib\site-packages\django\utils\dateparse.py", line 107, in parse_datetime match = datetime_re.match(value) TypeError: expected string or bytes-like object [22/Jul/2018 22:33:12] "GET /topics/1/ HTTP/1.1" 500 101852 Internal Server Error: /topics/1/ Traceback (most recent call last): File "d:\t_django\ll_env\lib\site-packages\django\core\handlers\exception.py", line 35, in inner response = get_response(request) File "d:\t_django\ll_env\lib\site-packages\django\core\handlers\base.py", line 128, in _get_response response = self.process_exception_by_middleware(e, request) File "d:\t_django\ll_env\lib\site-packages\django\core\handlers\base.py", line 126, in _get_response response = wrapped_callback(request, *callback_args, **callback_kwargs) File "d:\t_django\t_djangos\views.py", line 20, in topic topic = Topic.objects.get(id=topic_id) File "d:\t_django\ll_env\lib\site-packages\django\db\models\manager.py", line 82, in manager_method return getattr(self.get_queryset(), name)(*args, **kwargs) File "d:\t_django\ll_env\lib\site-packages\django\db\models\query.py", line 397, in get num = len(clone) File "d:\t_django\ll_env\lib\site-packages\django\db\models\query.py", line 254, in __len__ self._fetch_all() File "d:\t_django\ll_env\lib\site-packages\django\db\models\query.py", line 1179, in _fetch_all self._result_cache = list(self._iterable_class(self)) File "d:\t_django\ll_env\lib\site-packages\django\db\models\query.py", line 62, in __iter__ for row in compiler.results_iter(results): File "d:\t_django\ll_env\lib\site-packages\django\db\models\sql\compiler.py", line 1011, in apply_converters value = converter(value, expression, connection) File "d:\t_django\ll_env\lib\site-packages\django\db\backends\sqlite3\operations.py", line 222, in convert_datetimefield_value value = parse_datetime(value) File "d:\t_django\ll_env\lib\site-packages\django\utils\dateparse.py", line 107, in parse_datetime match = datetime_re.match(value) TypeError: expected string or bytes-like object |
8
getlost OP @Zzdex @inoki 是我搞错了,没有迁移数据,但是还是有问题
----------------------------HTML--------------------------- {% extends "t_djangos/base.html" %} {% block content %} <p>Topics:{{ topic }}</p> <p>Entries:</p> <ul> {% for entry in entries %} <li> <p>{{ entry.date_added|date:'M d, Y' H:i }}</p> <p>{{ entry.text|linebreaks }}</p> </li> {% empty %} <li> There are no entriesfor this topic yet. </li> {% endfor %} </ul> {% endblock content %} ----------------------------HTML--------------------------- <p>{{ entry.date_added|date:'M d, Y' H:i }}</p> 这一行并不在网页上显示出来 <p>{{ entry.text|linebreaks }}</p> 这个却会 |
9
inoki 2018-07-23 04:56:03 +08:00 via Android
|