环境:win8-64位、python372、django1.11.4
场景:根据教程在虚拟环境中创建了一个新的空django工程,尝试运行以下命令:
python manage.py runserver
这个命令启动网络服务器,然而执行后出现以下错误,且无法访问127.0.0.1:8000:
(venv) C:\Workspace\Python\myproject\myproject>python manage.py runserver
Unhandled exception in thread started by <function check_errors.<locals>.wrapper at 0x0000008F42BCED90>
Traceback (most recent call last):
File "C:\Workspace\Python\myproject\venv\lib\site-packages\django\utils\autoreload.py", line 228, in wrapper
fn(*args, **kwargs)
File "C:\Workspace\Python\myproject\venv\lib\site-packages\django\core\management\commands\runserver.py", line 117, in inner_run autoreload.raise_last_exception()
File "C:\Workspace\Python\myproject\venv\lib\site-packages\django\utils\autoreload.py", line 251, in raise_last_exception
six.reraise(*_exception)
File "C:\Workspace\Python\myproject\venv\lib\site-packages\django\utils\six.py", line 685, in reraise
raise value.with_traceback(tb)
File "C:\Workspace\Python\myproject\venv\lib\site-packages\django\utils\autoreload.py", line 228, in wrapper
fn(*args, **kwargs)
File "C:\Workspace\Python\myproject\venv\lib\site-packages\django\__init__.py", line 27, in setup
apps.populate(settings.INSTALLED_APPS)
File "C:\Workspace\Python\myproject\venv\lib\site-packages\django\apps\registry.py", line 85, in populate
app_config = AppConfig.create(entry)
File "C:\Workspace\Python\myproject\venv\lib\site-packages\django\apps\config.py", line 94, in create
module = import_module(entry)
File "C:\Workspace\Python\myproject\venv\lib\importlib\__init__.py", line 127,in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1006, in _gcd_import
File "<frozen importlib._bootstrap>", line 983, in _find_and_load
File "<frozen importlib._bootstrap>", line 967, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 677, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 728, in exec_module
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "C:\Workspace\Python\myproject\venv\lib\site-packages\django\contrib\admin\__init__.py", line 4, in <module>
from django.contrib.admin.filters import (
File "C:\Workspace\Python\myproject\venv\lib\site-packages\django\contrib\admin\filters.py", line 10, in <module>
from django.contrib.admin.options import IncorrectLookupParameters
File "C:\Workspace\Python\myproject\venv\lib\site-packages\django\contrib\admin\options.py", line 12, in <module>
from django.contrib.admin import helpers, widgets
File "C:\Workspace\Python\myproject\venv\lib\site-packages\django\contrib\admin\widgets.py", line 151
'%s=%s' % (k, v) for k, v in params.items(),
^
SyntaxError: Generator expression must be parenthesized
出现这个问题的原因是在\venv\lib\site-packages\django\contrib\admin\widgets.py文件中的line 151有以下语句语法错误:
'%s=%s' % (k, v) for k, v in params.items(),
此处末尾多了一个逗号
修改保存后重新执行,问题解决,显示如下信息:
(venv) C:\Workspace\Python\myproject\myproject>python manage.py runserver
Performing system checks...
System check identified no issues (0 silenced).
You have 13 unapplied migration(s). Your project may not work properly until you apply the migrations for app(s): admin, auth, contenttypes, sessions.
Run 'python manage.py migrate' to apply them.
January 19, 2019 - 22:57:49
Django version 1.11.4, using settings 'myproject.settings'
Starting development server at http://127.0.0.1:8000/
Quit the server with CTRL-BREAK.
[19/Jan/2019 23:01:51] "GET / HTTP/1.1" 200 1716
Not Found: /favicon.ico
[19/Jan/2019 23:01:51] "GET /favicon.ico HTTP/1.1" 404 1965
问题原因是python372与django1.11.4存在兼容问题
网友评论