一、将Django项目部署在Linux运行
报错:xadmin错误NameError:name 'reload' is not defined
Traceback (most recent call last):
File "/usr/local/python3/lib/python3.6/site-packages/django/utils/autoreload.py", line 228, in wrapper
fn(*args, **kwargs)
File "/usr/local/python3/lib/python3.6/site-packages/django/core/management/commands/runserver.py", line 116, in inner_run
autoreload.raise_last_exception()
File "/usr/local/python3/lib/python3.6/site-packages/django/utils/autoreload.py", line 251, in raise_last_exception
six.reraise(*_exception)
File "/usr/local/python3/lib/python3.6/site-packages/django/utils/six.py", line 685, in reraise
raise value.with_traceback(tb)
File "/usr/local/python3/lib/python3.6/site-packages/django/utils/autoreload.py", line 228, in wrapper
fn(*args, **kwargs)
File "/usr/local/python3/lib/python3.6/site-packages/django/__init__.py", line 27, in setup
apps.populate(settings.INSTALLED_APPS)
File "/usr/local/python3/lib/python3.6/site-packages/django/apps/registry.py", line 85, in populate
app_config = AppConfig.create(entry)
File "/usr/local/python3/lib/python3.6/site-packages/django/apps/config.py", line 94, in create
module = import_module(entry)
File "/usr/local/python3/lib/python3.6/importlib/__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 994, in _gcd_import
File "<frozen importlib._bootstrap>", line 971, in _find_and_load
File "<frozen importlib._bootstrap>", line 955, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 665, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 678, in exec_module
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "/usr/local/python3/lib/python3.6/site-packages/xadmin/__init__.py", line 4, in <module>
from xadmin.sites import AdminSite, site
File "/usr/local/python3/lib/python3.6/site-packages/xadmin/sites.py", line 9, in <module>
reload(sys)
NameError: name 'reload' is not defined
以及
importerror:cannot import name 'smart_unicode']
Traceback (most recent call last):
File "/usr/local/python3/lib/python3.6/site-packages/django/utils/autoreload.py", line 228, in wrapper
fn(*args, **kwargs)
File "/usr/local/python3/lib/python3.6/site-packages/django/core/management/commands/runserver.py", line 116, in inner_run
autoreload.raise_last_exception()
File "/usr/local/python3/lib/python3.6/site-packages/django/utils/autoreload.py", line 251, in raise_last_exception
six.reraise(*_exception)
File "/usr/local/python3/lib/python3.6/site-packages/django/utils/six.py", line 685, in reraise
raise value.with_traceback(tb)
File "/usr/local/python3/lib/python3.6/site-packages/django/utils/autoreload.py", line 228, in wrapper
fn(*args, **kwargs)
File "/usr/local/python3/lib/python3.6/site-packages/django/__init__.py", line 27, in setup
apps.populate(settings.INSTALLED_APPS)
File "/usr/local/python3/lib/python3.6/site-packages/django/apps/registry.py", line 108, in populate
app_config.import_models()
File "/usr/local/python3/lib/python3.6/site-packages/django/apps/config.py", line 202, in import_models
self.models_module = import_module(models_module_name)
File "/usr/local/python3/lib/python3.6/importlib/__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 994, in _gcd_import
File "<frozen importlib._bootstrap>", line 971, in _find_and_load
File "<frozen importlib._bootstrap>", line 955, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 665, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 678, in exec_module
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "/usr/local/python3/lib/python3.6/site-packages/xadmin/models.py", line 10, in <module>
from django.utils.encoding import smart_unicode
ImportError: cannot import name 'smart_unicode'
xadmin的版本有问题,因为大量使用了python2的模块,但在python3已然放弃这些模块,直接用以下命令安装即可:
pip install https://github.com/sshwsfc/xadmin/tarball/master
二 python3 manage.py runserver warning
/usr/local/python3/lib/python3.6/site-packages/pymysql/cursors.py:170: Warning: (3090, "Changing sql mode 'NO_AUTO_CREATE_USER' is deprecated. It will be removed in a future release.")
result = self._query(query)
修改项目setting的数据库设置,设置sql_mode=SET sql_mode='traditional'
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'HOST': '',
'PORT': '3306',
'NAME': '',
'USER': '',
'PASSWORD': '',
'OPTIONS': {
'init_command': "SET sql_mode='traditional'",
},
}
}
网友评论