以10为底的int()无效文字:b'25 18:12:59.592724'

时间:2019-05-05 09:27:21

标签: python django

我在Board模型中添加了以下两个功能,但我遇到了以上错误:

class Board(models.Model):
    name = models.CharField(max_length=150, unique=True)
    description = models.CharField(max_length=150)

    def __str__(self):
        return self.name

    def get_posts_count(self):
        return Post.objects.filter(topic__board=self).count()

    def get_last_post(self):
        return Post.objects.filter(topic__board=self).order_by('-created_at').first()

然后我应用了迁移 运行服务器后,我收到此错误,这是完整的引用:

Environment:


Request Method: GET
Request URL: http://localhost:8000/board/1/

Django Version: 2.2.1
Python Version: 3.7.2
Installed Applications:
['django.contrib.admin',
 'django.contrib.auth',
 'django.contrib.contenttypes',
 'django.contrib.sessions',
 'django.contrib.messages',
 'django.contrib.staticfiles',
 'board.apps.BoardConfig',
 'crispy_forms',
 'accounts',
 'widget_tweaks']
Installed Middleware:
['django.middleware.security.SecurityMiddleware',
 'django.contrib.sessions.middleware.SessionMiddleware',
 'django.middleware.common.CommonMiddleware',
 'django.middleware.csrf.CsrfViewMiddleware',
 'django.contrib.auth.middleware.AuthenticationMiddleware',
 'django.contrib.messages.middleware.MessageMiddleware',
 'django.middleware.clickjacking.XFrameOptionsMiddleware']


Template error:
In template C:\Users\Administrator\Desktop\board0a\src\board\templates\board\base.html, error at line 23
   invalid literal for int() with base 10: b'25 17:52:56.629918'
   13 :     <link rel="stylesheet" href="{% static 'css/mystyle.css' %}">
   14 : 
   15 :     {% block stylesheet %}
   16 :     {% endblock stylesheet %}
   17 : 
   18 : </head>
   19 : 
   20 : <body>
   21 :     <nav class="navbar navbar-expand-lg navbar-dark bg-dark">
   22 :         <a class="navbar-brand" href="{% url 'board:home' %}">Navbar</a>
   23 :         <button class="navbar-toggler" type="button" data-toggle="colla pse" data-target="#navbarSupportedC ontent"
   24 :             aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
   25 :             <span class="navbar-toggler-icon"></span>
   26 :         </button>
   27 : 
   28 :         <div class="collapse navbar-collapse" id="navbarSupportedContent">
   29 :             <ul class="navbar-nav mr-auto">
   30 :                 <li class="nav-item active">
   31 :                     <a class="nav-link" href="{% url 'board:home' %}">Home <span class="sr-only">(current)</span></a>
   32 :                 </li>
   33 :                 <li class="nav-item">


Traceback:

File "C:\Users\Administrator\AppData\Local\Programs\Python\Python37\lib\site-packages\django\core\handlers\exception.py" in inner
  34.             response = get_response(request)

File "C:\Users\Administrator\AppData\Local\Programs\Python\Python37\lib\site-packages\django\core\handlers\base.py" in _get_response
  115.                 response = self.process_exception_by_middleware(e, request)

File "C:\Users\Administrator\AppData\Local\Programs\Python\Python37\lib\site-packages\django\core\handlers\base.py" in _get_response
  113.                 response = wrapped_callback(request, *callback_args, **callback_kwargs)

File "C:\Users\Administrator\Desktop\board0a\src\board\views.py" in board_topics
  15.     return render(request, 'board/board_topics.html', {'board': board})

File "C:\Users\Administrator\AppData\Local\Programs\Python\Python37\lib\site-packages\django\shortcuts.py" in render
  36.     content = loader.render_to_string(template_name, context, request, using=using)

File "C:\Users\Administrator\AppData\Local\Programs\Python\Python37\lib\site-packages\django\template\loader.py" in render_to_string
  62.     return template.render(context, request)

File "C:\Users\Administrator\AppData\Local\Programs\Python\Python37\lib\site-packages\django\template\backends\django.py" in render
  61.             return self.template.render(context)

File "C:\Users\Administrator\AppData\Local\Programs\Python\Python37\lib\site-packages\django\template\base.py" in render
  171.                     return self._render(context)

File "C:\Users\Administrator\AppData\Local\Programs\Python\Python37\lib\site-packages\django\template\base.py" in _render
  163.         return self.nodelist.render(context)

File "C:\Users\Administrator\AppData\Local\Programs\Python\Python37\lib\site-packages\django\template\base.py" in render
  937.                 bit = node.render_annotated(context)

File "C:\Users\Administrator\AppData\Local\Programs\Python\Python37\lib\site-packages\django\template\base.py" in render_annotated
  904.             return self.render(context)

File "C:\Users\Administrator\AppData\Local\Programs\Python\Python37\lib\site-packages\django\template\loader_tags.py" in render
  150.             return compiled_parent._render(context)

File "C:\Users\Administrator\AppData\Local\Programs\Python\Python37\lib\site-packages\django\template\base.py" in _render
  163.         return self.nodelist.render(context)

File "C:\Users\Administrator\AppData\Local\Programs\Python\Python37\lib\site-packages\django\template\base.py" in render
  937.                 bit = node.render_annotated(context)

File "C:\Users\Administrator\AppData\Local\Programs\Python\Python37\lib\site-packages\django\template\base.py" in render_annotated
  904.             return self.render(context)

File "C:\Users\Administrator\AppData\Local\Programs\Python\Python37\lib\site-packages\django\template\loader_tags.py" in render
  62.                 result = block.nodelist.render(context)

File "C:\Users\Administrator\AppData\Local\Programs\Python\Python37\lib\site-packages\django\template\base.py" in render
  937.                 bit = node.render_annotated(context)

File "C:\Users\Administrator\AppData\Local\Programs\Python\Python37\lib\site-packages\django\template\base.py" in render_annotated
  904.             return self.render(context)

File "C:\Users\Administrator\AppData\Local\Programs\Python\Python37\lib\site-packages\django\template\defaulttags.py" in render
  166.             len_values = len(values)

File "C:\Users\Administrator\AppData\Local\Programs\Python\Python37\lib\site-packages\django\db\models\query.py" in __len__
  256.         self._fetch_all()

File "C:\Users\Administrator\AppData\Local\Programs\Python\Python37\lib\site-packages\django\db\models\query.py" in _fetch_all
  1242.             self._result_cache = list(self._iterable_class(self))

File "C:\Users\Administrator\AppData\Local\Programs\Python\Python37\lib\site-packages\django\db\models\query.py" in __iter__
  55.         results = compiler.execute_sql(chunked_fetch=self.chunked_fetch, chunk_size=self.chunk_size)

File "C:\Users\Administrator\AppData\Local\Programs\Python\Python37\lib\site-packages\django\db\models\sql\compiler.py" in execute_sql
  1100.             cursor.execute(sql, params)

File "C:\Users\Administrator\AppData\Local\Programs\Python\Python37\lib\site-packages\django\db\backends\utils.py" in execute
  99.             return super().execute(sql, params)

File "C:\Users\Administrator\AppData\Local\Programs\Python\Python37\lib\site-packages\django\db\backends\utils.py" in execute
  67.         return self._execute_with_wrappers(sql, params, many=False, executor=self._execute)

File "C:\Users\Administrator\AppData\Local\Programs\Python\Python37\lib\site-packages\django\db\backends\utils.py" in _execute_with_wrappers
  76.         return executor(sql, params, many, context)

File "C:\Users\Administrator\AppData\Local\Programs\Python\Python37\lib\site-packages\django\db\backends\utils.py" in _execute
  84.                 return self.cursor.execute(sql, params)

File "C:\Users\Administrator\AppData\Local\Programs\Python\Python37\lib\site-packages\django\db\backends\sqlite3\base.py" in execute
  383.         return Database.Cursor.execute(self, query, params)

File "C:\Users\Administrator\AppData\Local\Programs\Python\Python37\lib\sqlite3\dbapi2.py" in convert_date
  64.         return datetime.date(*map(int, val.split(b"-")))

Exception Type: ValueError at /board/1/
Exception Value: invalid literal for int() with base 10: b'25 17:52:56.629918'

在这些地方的某个地方我做错了我得到这个错误。希望您能帮助我,非常感谢。

0 个答案:

没有答案