python -Wd manage.py runserver
python -Wa manage.py runserver
一共有四类:
第一类:RemovedInDjango20Warning: on_delete will be a required arg for ForeignKey in Django 2.0
第二类:RemovedInDjango20Warning: Old-style middleware using settings.MIDDLEWARE_CLASSES is deprecated. Update your middleware and use settings.MIDDLEWARE instead.
第三类:RemovedInDjango20Warning: assignment_tag() is deprecated. Use simple_tag() instead
第四类: ImportWarning: Not importing directory
这些警告主要是升级到2.0要修复的问题,暂不处理
python manage.py migrate
执行报错一:ValueError: Unable to configure handler 'null': Cannot resolve 'django.utils.log.NullHandler': No module named NullHandler日志:
patch_clear to support prefix clear
Traceback (most recent call last):
File "manage.py", line 18, in <module>
execute_from_command_line(sys.argv)
File "/Users/pitou/.virtualenvs/itsm_migrate/lib/python2.7/site-packages/django/core/management/__init__.py", line 363, in execute_from_command_line
utility.execute()
File "/Users/pitou/.virtualenvs/itsm_migrate/lib/python2.7/site-packages/django/core/management/__init__.py", line 337, in execute
django.setup()
File "/Users/pitou/.virtualenvs/itsm_migrate/lib/python2.7/site-packages/django/__init__.py", line 22, in setup
configure_logging(settings.LOGGING_CONFIG, settings.LOGGING)
File "/Users/pitou/.virtualenvs/itsm_migrate/lib/python2.7/site-packages/django/utils/log.py", line 75, in configure_logging
logging_config_func(logging_settings)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/logging/config.py", line 794, in dictConfig
dictConfigClass(config).configure()
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/logging/config.py", line 576, in configure
'%r: %s' % (name, e))
ValueError: Unable to configure handler 'null': Cannot resolve 'django.utils.log.NullHandler': No module named NullHandler
Google:
日志配置错误
解决方法:
# 日志配置部分的代码
django.utils.log.NullHandler => logging.NullHandler
python manage.py migrate
执行报错二:django.core.exceptions.AppRegistryNotReady: Apps aren't loaded yet.日志详情:
(itsm_migrate) ➜ itsm_develop git:(migrate) python manage.py migrate
patch_clear to support prefix clear
Traceback (most recent call last):
File "manage.py", line 18, in <module>
execute_from_command_line(sys.argv)
File "/Users/pitou/.virtualenvs/itsm_migrate/lib/python2.7/site-packages/django/core/management/__init__.py", line 363, in execute_from_command_line
utility.execute()
File "/Users/pitou/.virtualenvs/itsm_migrate/lib/python2.7/site-packages/django/core/management/__init__.py", line 337, in execute
django.setup()
File "/Users/pitou/.virtualenvs/itsm_migrate/lib/python2.7/site-packages/django/__init__.py", line 27, in setup
apps.populate(settings.INSTALLED_APPS)
File "/Users/pitou/.virtualenvs/itsm_migrate/lib/python2.7/site-packages/django/apps/registry.py", line 85, in populate
app_config = AppConfig.create(entry)
File "/Users/pitou/.virtualenvs/itsm_migrate/lib/python2.7/site-packages/django/apps/config.py", line 120, in create
mod = import_module(mod_path)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/importlib/__init__.py", line 37, in import_module
__import__(name)
File "/Users/pitou/PycharmProjects/itsm_develop/service/apps.py", line 12, in <module>
from service.models import (
File "/Users/pitou/PycharmProjects/itsm_develop/service/models.py", line 13, in <module>
from mptt.models import MPTTModel, TreeForeignKey
File "/Users/pitou/.virtualenvs/itsm_migrate/lib/python2.7/site-packages/mptt/models.py", line 377, in <module>
class MPTTModel(six.with_metaclass(MPTTModelBase, models.Model)):
File "/Users/pitou/.virtualenvs/itsm_migrate/lib/python2.7/site-packages/django/utils/six.py", line 808, in __new__
return meta(name, bases, d)
File "/Users/pitou/.virtualenvs/itsm_migrate/lib/python2.7/site-packages/mptt/models.py", line 264, in __new__
cls = super_new(meta, class_name, bases, class_dict)
File "/Users/pitou/.virtualenvs/itsm_migrate/lib/python2.7/site-packages/django/db/models/base.py", line 110, in __new__
app_config = apps.get_containing_app_config(module)
File "/Users/pitou/.virtualenvs/itsm_migrate/lib/python2.7/site-packages/django/apps/registry.py", line 247, in get_containing_app_config
self.check_apps_ready()
File "/Users/pitou/.virtualenvs/itsm_migrate/lib/python2.7/site-packages/django/apps/registry.py", line 125, in check_apps_ready
raise AppRegistryNotReady("Apps aren't loaded yet.")
django.core.exceptions.AppRegistryNotReady: Apps aren't loaded yet.
Google:
https://groups.google.com/forum/#!topic/django-users/bF_lRbzzguA
https://docs.djangoproject.com/en/1.9/ref/applications/#how-applications-are-loaded
The problem is that one of your applications (foo.app.scripts) imports
models in its top-level __init__.py. This is not supported; for an
explanation, you can read
解决方案:
修改apps.py
文件
# 移动到函数内部
# from role.models import RoleType, UserRole
def app_ready_handler(sender, **kwargs):
print 'init builtin roles and user roles data'
from role.models import RoleType, UserRole
try:
RoleType.init_builtin_roles()
UserRole.init_builtin_user_roles()
except Exception as e:
print 'init builtin roles and user roles data exception: %s' % e
python manage.py migrate
报错:django.core.exceptions.ImproperlyConfigured: MySQLdb/mysqlclient 1.2.3 or newer is required; you have 0.6.7.None
日志详情:
(itsm_migrate) ➜ itsm_develop git:(migrate) ✗ python manage.py migrate
patch_clear to support prefix clear
Traceback (most recent call last):
File "manage.py", line 18, in <module>
execute_from_command_line(sys.argv)
File "/Users/pitou/.virtualenvs/itsm_migrate/lib/python2.7/site-packages/django/core/management/__init__.py", line 363, in execute_from_command_line
utility.execute()
File "/Users/pitou/.virtualenvs/itsm_migrate/lib/python2.7/site-packages/django/core/management/__init__.py", line 337, in execute
django.setup()
File "/Users/pitou/.virtualenvs/itsm_migrate/lib/python2.7/site-packages/django/__init__.py", line 27, in setup
apps.populate(settings.INSTALLED_APPS)
File "/Users/pitou/.virtualenvs/itsm_migrate/lib/python2.7/site-packages/django/apps/registry.py", line 108, in populate
app_config.import_models()
File "/Users/pitou/.virtualenvs/itsm_migrate/lib/python2.7/site-packages/django/apps/config.py", line 202, in import_models
self.models_module = import_module(models_module_name)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/importlib/__init__.py", line 37, in import_module
__import__(name)
File "/Users/pitou/.virtualenvs/itsm_migrate/lib/python2.7/site-packages/django/contrib/auth/models.py", line 4, in <module>
from django.contrib.auth.base_user import AbstractBaseUser, BaseUserManager
File "/Users/pitou/.virtualenvs/itsm_migrate/lib/python2.7/site-packages/django/contrib/auth/base_user.py", line 52, in <module>
class AbstractBaseUser(models.Model):
File "/Users/pitou/.virtualenvs/itsm_migrate/lib/python2.7/site-packages/django/db/models/base.py", line 124, in __new__
new_class.add_to_class('_meta', Options(meta, app_label))
File "/Users/pitou/.virtualenvs/itsm_migrate/lib/python2.7/site-packages/django/db/models/base.py", line 330, in add_to_class
value.contribute_to_class(cls, name)
File "/Users/pitou/.virtualenvs/itsm_migrate/lib/python2.7/site-packages/django/db/models/options.py", line 214, in contribute_to_class
self.db_table = truncate_name(self.db_table, connection.ops.max_name_length())
File "/Users/pitou/.virtualenvs/itsm_migrate/lib/python2.7/site-packages/django/db/__init__.py", line 33, in __getattr__
return getattr(connections[DEFAULT_DB_ALIAS], item)
File "/Users/pitou/.virtualenvs/itsm_migrate/lib/python2.7/site-packages/django/db/utils.py", line 211, in __getitem__
backend = load_backend(db['ENGINE'])
File "/Users/pitou/.virtualenvs/itsm_migrate/lib/python2.7/site-packages/django/db/utils.py", line 115, in load_backend
return import_module('%s.base' % backend_name)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/importlib/__init__.py", line 37, in import_module
__import__(name)
File "/Users/pitou/.virtualenvs/itsm_migrate/lib/python2.7/site-packages/django/db/backends/mysql/base.py", line 49, in <module>
% Database.__version__
django.core.exceptions.ImproperlyConfigured: MySQLdb/mysqlclient 1.2.3 or newer is required; you have 0.6.7.None
Google:
try:
import MySQLdb as Database
except ImportError as e:
raise ImproperlyConfigured(
'Error loading MySQLdb module: %s.\n'
'Did you install mysqlclient or MySQL-python?' % e
)
# django/db/backends/mysql/base.py", line 49
version = Database.version_info
if version < (1, 2, 3):
raise ImproperlyConfigured(
"MySQLdb/mysqlclient 1.2.3 or newer is required; you have %s"
% Database.__version__
)
# pymysql.__init__.py + 102
# we include a doctored version_info here for MySQLdb compatibility
version_info = (1,2,2,"final",0)
https://blog.csdn.net/cc9200/article/details/82871310
https://blog.csdn.net/qq_35304570/article/details/79674449
http://www.programmersought.com/article/7236248863/
解决方案:
# Database
# https://docs.djangoproject.com/en/1.8/ref/settings/#databases
try:
import pymysql
pymysql.install_as_MySQLdb()
# Patch version info to forcely pass Django client check > 1.2.3
setattr(pymysql, 'version_info', (1, 2, 6, "final", 0))
except ImportError as e:
raise ImportError("PyMySQL is not installed: %s" % e)
python manage.py migrate
报错:AttributeError: 'module' object has no attribute 'get_app'
日志详情:
(itsm_migrate) ➜ itsm_develop git:(migrate) ✗ python manage.py migrate
patch_clear to support prefix clear
Traceback (most recent call last):
File "manage.py", line 18, in <module>
execute_from_command_line(sys.argv)
File "/Users/pitou/.virtualenvs/itsm_migrate/lib/python2.7/site-packages/django/core/management/__init__.py", line 363, in execute_from_command_line
utility.execute()
File "/Users/pitou/.virtualenvs/itsm_migrate/lib/python2.7/site-packages/django/core/management/__init__.py", line 337, in execute
django.setup()
File "/Users/pitou/.virtualenvs/itsm_migrate/lib/python2.7/site-packages/django/__init__.py", line 27, in setup
apps.populate(settings.INSTALLED_APPS)
File "/Users/pitou/.virtualenvs/itsm_migrate/lib/python2.7/site-packages/django/apps/registry.py", line 116, in populate
app_config.ready()
File "/Users/pitou/.virtualenvs/itsm_migrate/lib/python2.7/site-packages/django/contrib/admin/apps.py", line 23, in ready
self.module.autodiscover()
File "/Users/pitou/.virtualenvs/itsm_migrate/lib/python2.7/site-packages/django/contrib/admin/__init__.py", line 26, in autodiscover
autodiscover_modules('admin', register_to=site)
File "/Users/pitou/.virtualenvs/itsm_migrate/lib/python2.7/site-packages/django/utils/module_loading.py", line 50, in autodiscover_modules
import_module('%s.%s' % (app_config.name, module_to_search))
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/importlib/__init__.py", line 37, in import_module
__import__(name)
File "/Users/pitou/PycharmProjects/itsm_develop/workflow/admin.py", line 6, in <module>
auto_configure_admin(applications=['workflow', 'service', 'ticket', 'role'])
File "/Users/pitou/.virtualenvs/itsm_migrate/lib/python2.7/site-packages/django_smart_autoregister/auto_register.py", line 130, in auto_configure_admin
apps = get_apps(applications, exclude_applications)
File "/Users/pitou/.virtualenvs/itsm_migrate/lib/python2.7/site-packages/django_smart_autoregister/django_helper.py", line 40, in get_apps
applications.append(models.get_app(app_label))
AttributeError: 'module' object has no attribute 'get_app'
Google:
django-smart-autoregister 不兼容1.11
Compatibility
Tested with Django 1.4, 1.5, 1.6, 1.7, 1.8
Tested with Python 2.7, 3.3, 3.4 and PyPy
# models中没有get_app方法
File "/Users/pitou/.virtualenvs/itsm_migrate/lib/python2.7/site-packages/django_smart_autoregister/django_helper.py", line 40, in get_apps
applications.append(models.get_app(app_label))
models.get_app
# https://github.com/bmihelac/django-cruds/issues/3
# Latest supported Django is 1.11
解决方案:
TODO:
fork django-smart-autoregister
,并修改兼容1.11
(干脆先注释了吧,不影响主功能)
# workflow/admin.py
# auto_configure_admin(applications=['workflow', 'service', 'ticket', 'role'])
python manage.py migrate
报错:from django.conf.urls import include, patterns, url ImportError: cannot import name patterns
日志详情:
(itsm_migrate) ➜ itsm_develop git:(migrate) ✗ python manage.py migrate
patch_clear to support prefix clear
Traceback (most recent call last):
File "manage.py", line 18, in <module>
execute_from_command_line(sys.argv)
File "/Users/pitou/.virtualenvs/itsm_migrate/lib/python2.7/site-packages/django/core/management/__init__.py", line 363, in execute_from_command_line
utility.execute()
File "/Users/pitou/.virtualenvs/itsm_migrate/lib/python2.7/site-packages/django/core/management/__init__.py", line 355, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/Users/pitou/.virtualenvs/itsm_migrate/lib/python2.7/site-packages/django/core/management/base.py", line 283, in run_from_argv
self.execute(*args, **cmd_options)
File "/Users/pitou/.virtualenvs/itsm_migrate/lib/python2.7/site-packages/django/core/management/base.py", line 327, in execute
self.check()
File "/Users/pitou/.virtualenvs/itsm_migrate/lib/python2.7/site-packages/django/core/management/base.py", line 359, in check
include_deployment_checks=include_deployment_checks,
File "/Users/pitou/.virtualenvs/itsm_migrate/lib/python2.7/site-packages/django/core/management/commands/migrate.py", line 62, in _run_checks
issues.extend(super(Command, self)._run_checks(**kwargs))
File "/Users/pitou/.virtualenvs/itsm_migrate/lib/python2.7/site-packages/django/core/management/base.py", line 346, in _run_checks
return checks.run_checks(**kwargs)
File "/Users/pitou/.virtualenvs/itsm_migrate/lib/python2.7/site-packages/django/core/checks/registry.py", line 81, in run_checks
new_errors = check(app_configs=app_configs)
File "/Users/pitou/.virtualenvs/itsm_migrate/lib/python2.7/site-packages/django/core/checks/urls.py", line 16, in check_url_config
return check_resolver(resolver)
File "/Users/pitou/.virtualenvs/itsm_migrate/lib/python2.7/site-packages/django/core/checks/urls.py", line 26, in check_resolver
return check_method()
File "/Users/pitou/.virtualenvs/itsm_migrate/lib/python2.7/site-packages/django/urls/resolvers.py", line 254, in check
for pattern in self.url_patterns:
File "/Users/pitou/.virtualenvs/itsm_migrate/lib/python2.7/site-packages/django/utils/functional.py", line 35, in __get__
res = instance.__dict__[self.name] = self.func(instance)
File "/Users/pitou/.virtualenvs/itsm_migrate/lib/python2.7/site-packages/django/urls/resolvers.py", line 405, in url_patterns
patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module)
File "/Users/pitou/.virtualenvs/itsm_migrate/lib/python2.7/site-packages/django/utils/functional.py", line 35, in __get__
res = instance.__dict__[self.name] = self.func(instance)
File "/Users/pitou/.virtualenvs/itsm_migrate/lib/python2.7/site-packages/django/urls/resolvers.py", line 398, in urlconf_module
return import_module(self.urlconf_name)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/importlib/__init__.py", line 37, in import_module
__import__(name)
File "/Users/pitou/PycharmProjects/itsm_develop/urls.py", line 10, in <module>
from django.conf.urls import include, patterns, url
ImportError: cannot import name patterns
Google:
https://stackoverflow.com/questions/38786036/importerror-cannot-import-name-patterns
Use of patterns is deprecated since django 1.8. See docs. You can use plain lists now.
https://docs.djangoproject.com/en/1.10/releases/1.10/#features-removed-in-1-10
Support for calling a SQLCompiler directly as an alias for calling its quote_name_unless_alias method is removed.
The cycle and firstof template tags are removed from the future template tag library.
django.conf.urls.patterns() is removed.
Support for the prefix argument to django.conf.urls.i18n.i18n_patterns() is removed.
解决方案:
修改用到patterns
的urls.py
# 修改前
from django.conf.urls import patterns, url
urlpatterns = patterns(
'misc.views',
url(r'^upload_file/$', 'upload'),
url(r'^download_file/$', 'download'),
url(r'^export_workflows/$', 'export_workflows'),
url(r'^import_workflows/$', 'import_workflows'),
url(r'^clean_cache/$', 'clean_cache'),
)
# 修改后
from django.conf.urls import url
from misc import views
urlpatterns = [
url(r'^upload_file/$', views.upload),
url(r'^download_file/$', views.download),
url(r'^export_workflows/$', views.export_workflows),
url(r'^import_workflows/$', views.import_workflows),
url(r'^clean_cache/$', views.clean_cache),
]
python manage.py migrate
报错:ImportError: cannot import name FileWrapper
日志详情:
(itsm_migrate) ➜ itsm_develop git:(migrate) ✗ python manage.py migrate
patch_clear to support prefix clear
Traceback (most recent call last):
File "manage.py", line 18, in <module>
execute_from_command_line(sys.argv)
File "/Users/pitou/.virtualenvs/itsm_migrate/lib/python2.7/site-packages/django/core/management/__init__.py", line 363, in execute_from_command_line
utility.execute()
File "/Users/pitou/.virtualenvs/itsm_migrate/lib/python2.7/site-packages/django/core/management/__init__.py", line 355, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/Users/pitou/.virtualenvs/itsm_migrate/lib/python2.7/site-packages/django/core/management/base.py", line 283, in run_from_argv
self.execute(*args, **cmd_options)
File "/Users/pitou/.virtualenvs/itsm_migrate/lib/python2.7/site-packages/django/core/management/base.py", line 327, in execute
self.check()
File "/Users/pitou/.virtualenvs/itsm_migrate/lib/python2.7/site-packages/django/core/management/base.py", line 359, in check
include_deployment_checks=include_deployment_checks,
File "/Users/pitou/.virtualenvs/itsm_migrate/lib/python2.7/site-packages/django/core/management/commands/migrate.py", line 62, in _run_checks
issues.extend(super(Command, self)._run_checks(**kwargs))
File "/Users/pitou/.virtualenvs/itsm_migrate/lib/python2.7/site-packages/django/core/management/base.py", line 346, in _run_checks
return checks.run_checks(**kwargs)
File "/Users/pitou/.virtualenvs/itsm_migrate/lib/python2.7/site-packages/django/core/checks/registry.py", line 81, in run_checks
new_errors = check(app_configs=app_configs)
File "/Users/pitou/.virtualenvs/itsm_migrate/lib/python2.7/site-packages/django/core/checks/urls.py", line 16, in check_url_config
return check_resolver(resolver)
File "/Users/pitou/.virtualenvs/itsm_migrate/lib/python2.7/site-packages/django/core/checks/urls.py", line 26, in check_resolver
return check_method()
File "/Users/pitou/.virtualenvs/itsm_migrate/lib/python2.7/site-packages/django/urls/resolvers.py", line 254, in check
for pattern in self.url_patterns:
File "/Users/pitou/.virtualenvs/itsm_migrate/lib/python2.7/site-packages/django/utils/functional.py", line 35, in __get__
res = instance.__dict__[self.name] = self.func(instance)
File "/Users/pitou/.virtualenvs/itsm_migrate/lib/python2.7/site-packages/django/urls/resolvers.py", line 405, in url_patterns
patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module)
File "/Users/pitou/.virtualenvs/itsm_migrate/lib/python2.7/site-packages/django/utils/functional.py", line 35, in __get__
res = instance.__dict__[self.name] = self.func(instance)
File "/Users/pitou/.virtualenvs/itsm_migrate/lib/python2.7/site-packages/django/urls/resolvers.py", line 398, in urlconf_module
return import_module(self.urlconf_name)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/importlib/__init__.py", line 37, in import_module
__import__(name)
File "/Users/pitou/PycharmProjects/itsm_develop/urls.py", line 22, in <module>
url(r'^api/', include('api.v1')),
File "/Users/pitou/.virtualenvs/itsm_migrate/lib/python2.7/site-packages/django/conf/urls/__init__.py", line 50, in include
urlconf_module = import_module(urlconf_module)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/importlib/__init__.py", line 37, in import_module
__import__(name)
File "/Users/pitou/PycharmProjects/itsm_develop/api/v1.py", line 26, in <module>
url(r'^misc/', include('misc.urls')),
File "/Users/pitou/.virtualenvs/itsm_migrate/lib/python2.7/site-packages/django/conf/urls/__init__.py", line 50, in include
urlconf_module = import_module(urlconf_module)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/importlib/__init__.py", line 37, in import_module
__import__(name)
File "/Users/pitou/PycharmProjects/itsm_develop/misc/urls.py", line 5, in <module>
from misc import views
File "/Users/pitou/PycharmProjects/itsm_develop/misc/views.py", line 14, in <module>
from django.core.servers.basehttp import FileWrapper
ImportError: cannot import name FileWrapper
Google:
https://github.com/MobSF/Mobile-Security-Framework-MobSF/issues/159
Fixes
Support for DJango 1.10
urls.py
import MobSF.views
Cannot import name FileWrapper
Exception Type: ImportError
Exception Value:
cannot import name FileWrapper
Exception Location: C:\Users\abcdef\Desktop\Mobile-Security-Framework-MobSF-0.9.2\MobSF\views.py in , line 8
views.py :
from django.core.servers.basehttp import FileWrapper
to
from wsgiref.util import FileWrapper
解决方案:
from wsgiref.util import FileWrapper
python manage.py migrate
报错:TypeError: view must be a callable or a list/tuple in the case of include().
日志详情:
(itsm_migrate) ➜ itsm_develop git:(migrate) ✗ python manage.py migrate
patch_clear to support prefix clear
Traceback (most recent call last):
File "manage.py", line 18, in <module>
execute_from_command_line(sys.argv)
File "/Users/pitou/.virtualenvs/itsm_migrate/lib/python2.7/site-packages/django/core/management/__init__.py", line 363, in execute_from_command_line
utility.execute()
File "/Users/pitou/.virtualenvs/itsm_migrate/lib/python2.7/site-packages/django/core/management/__init__.py", line 355, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/Users/pitou/.virtualenvs/itsm_migrate/lib/python2.7/site-packages/django/core/management/base.py", line 283, in run_from_argv
self.execute(*args, **cmd_options)
File "/Users/pitou/.virtualenvs/itsm_migrate/lib/python2.7/site-packages/django/core/management/base.py", line 327, in execute
self.check()
File "/Users/pitou/.virtualenvs/itsm_migrate/lib/python2.7/site-packages/django/core/management/base.py", line 359, in check
include_deployment_checks=include_deployment_checks,
File "/Users/pitou/.virtualenvs/itsm_migrate/lib/python2.7/site-packages/django/core/management/commands/migrate.py", line 62, in _run_checks
issues.extend(super(Command, self)._run_checks(**kwargs))
File "/Users/pitou/.virtualenvs/itsm_migrate/lib/python2.7/site-packages/django/core/management/base.py", line 346, in _run_checks
return checks.run_checks(**kwargs)
File "/Users/pitou/.virtualenvs/itsm_migrate/lib/python2.7/site-packages/django/core/checks/registry.py", line 81, in run_checks
new_errors = check(app_configs=app_configs)
File "/Users/pitou/.virtualenvs/itsm_migrate/lib/python2.7/site-packages/django/core/checks/urls.py", line 16, in check_url_config
return check_resolver(resolver)
File "/Users/pitou/.virtualenvs/itsm_migrate/lib/python2.7/site-packages/django/core/checks/urls.py", line 26, in check_resolver
return check_method()
File "/Users/pitou/.virtualenvs/itsm_migrate/lib/python2.7/site-packages/django/urls/resolvers.py", line 254, in check
for pattern in self.url_patterns:
File "/Users/pitou/.virtualenvs/itsm_migrate/lib/python2.7/site-packages/django/utils/functional.py", line 35, in __get__
res = instance.__dict__[self.name] = self.func(instance)
File "/Users/pitou/.virtualenvs/itsm_migrate/lib/python2.7/site-packages/django/urls/resolvers.py", line 405, in url_patterns
patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module)
File "/Users/pitou/.virtualenvs/itsm_migrate/lib/python2.7/site-packages/django/utils/functional.py", line 35, in __get__
res = instance.__dict__[self.name] = self.func(instance)
File "/Users/pitou/.virtualenvs/itsm_migrate/lib/python2.7/site-packages/django/urls/resolvers.py", line 398, in urlconf_module
return import_module(self.urlconf_name)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/importlib/__init__.py", line 37, in import_module
__import__(name)
File "/Users/pitou/PycharmProjects/itsm_develop/urls.py", line 46, in <module>
'django.views.static.serve', {'document_root': settings.MEDIA_ROOT}),
File "/Users/pitou/.virtualenvs/itsm_migrate/lib/python2.7/site-packages/django/conf/urls/__init__.py", line 85, in url
raise TypeError('view must be a callable or a list/tuple in the case of include().')
TypeError: view must be a callable or a list/tuple in the case of include().
Google:
Django 1.10 no longer allows you to specify views as a string (e.g. 'myapp.views.home') in your URL patterns.
The solution is to update your urls.py to include the view callable. This means that you have to import the view in your urls.py. If your URL patterns don't have names, then now is a good time to add one, because reversing with the dotted python path no longer works.
解决方案:
# 全局生效:不推荐生产环境使用
urlpatterns += [
# wiki上传图片404也可以这样简单解决:路由层面不复用MEDIA_URL,后者只用来生成url,比如可以自定义prefix为SITE_URL
url(r'^media/(?P<path>.*)$',
'django.views.static.serve', {'document_root': settings.MEDIA_ROOT}),
]
修改为
from django.views import static
# 全局生效:不推荐生产环境使用
urlpatterns += [
# wiki上传图片404也可以这样简单解决:路由层面不复用MEDIA_URL,后者只用来生成url,比如可以自定义prefix为SITE_URL
url(r'^media/(?P<path>.*)$',
static.serve, {'document_root': settings.MEDIA_ROOT}),
]
原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。
原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。