【问题标题】:Can I get django-oscar to work under Python 3?我可以让 django-oscar 在 Python 3 下工作吗?
【发布时间】:2017-03-08 21:19:12
【问题描述】:

我正在使用 Python 3.6.0、Django 1.10.6 和 Oscar 版本 1.4.0 final。

我已经看到一些类似的错误消息被讨论并报告了某些解决方案(例如,更新“仍然”是旧时自动生成的 wsgi.py),或者添加 import djangodjango.setup() 几乎接近顶部(即在SECRET_KEYINSTALLED_APPS 之前,在顶部附近向上移动)。我在 Github 上找到了与错误消息更接近的匹配项,出于 Raven 的目的,人们已经完全清楚地可以从他们的项目中删除标准用户或身份验证模块。但是,我还没有找到有人报告错误的地方,并且除了从不相关的基于 Django 的项目中删除标准 Django 应用程序之外,还有其他解决方案。

具体的错误消息和跟踪并没有告诉我有问题的行超出了怀疑它是由在 INSTALLED_APPS 中包含“django.contrib.contenttypes”触发的。我尝试运行它时得到的跟踪是:

(store-env) ~/store $ python manage.py migrate
回溯(最近一次通话最后):
   中的文件“manage.py”,第 22 行
    execute_from_command_line(sys.argv)
  文件“/Users/christos/store-env/lib/python3.6/site-packages/django/core/management/__init__.py”,第 367 行,在 execute_from_command_line
    实用程序.execute()
  文件“/Users/christos/store-env/lib/python3.6/site-packages/django/core/management/__init__.py”,第 359 行,在执行
    self.fetch_command(子命令).run_from_argv(self.argv)
  文件“/Users/christos/store-env/lib/python3.6/site-packages/django/core/management/base.py”,第 294 行,在 run_from_argv
    self.execute(*args, **cmd_options)
  文件“/Users/christos/store-env/lib/python3.6/site-packages/django/core/management/base.py”,第 342 行,在执行
    自行检查()
  检查文件“/Users/christos/store-env/lib/python3.6/site-packages/django/core/management/base.py”,第 374 行
    include_deployment_checks=include_deployment_checks,
  _run_checks 中的文件“/Users/christos/store-env/lib/python3.6/site-packages/django/core/management/commands/migrate.py”,第 62 行
    问题.扩展(超级(命令,自我)._run_checks(**kwargs))
  _run_checks 中的文件“/Users/christos/store-env/lib/python3.6/site-packages/django/core/management/base.py”,第 361 行
    返回 checks.run_checks(**kwargs)
  文件“/Users/christos/store-env/lib/python3.6/site-packages/django/core/checks/registry.py”,第 81 行,在 run_checks
    new_errors = 检查(app_configs=app_configs)
  文件“/Users/christos/store-env/lib/python3.6/site-packages/django/core/checks/urls.py”,第 14 行,在 check_url_config
    返回 check_resolver(解析器)
  文件“/Users/christos/store-env/lib/python3.6/site-packages/django/core/checks/urls.py”,第 24 行,在 check_resolver
    对于 resolver.url_patterns 中的模式:
  文件“/Users/christos/store-env/lib/python3.6/site-packages/django/utils/functional.py”,第 35 行,在 __get__
    res = instance.__dict__[self.name] = self.func(instance)
  文件“/Users/christos/store-env/lib/python3.6/site-packages/django/urls/resolvers.py”,第 313 行,在 url_patterns
    模式= getattr(self.urlconf_module,“urlpatterns”,self.urlconf_module)
  文件“/Users/christos/store-env/lib/python3.6/site-packages/django/utils/functional.py”,第 35 行,在 __get__
    res = instance.__dict__[self.name] = self.func(instance)
  文件“/Users/christos/store-env/lib/python3.6/site-packages/django/urls/resolvers.py”,第 306 行,在 urlconf_module
    返回 import_module(self.urlconf_name)
  文件“/Users/christos/store-env/lib/python3.6/importlib/__init__.py”,第 126 行,在 import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  _gcd_import 中的文件“”,第 978 行
  _find_and_load 中的文件“”,第 961 行
  _find_and_load_unlocked 中的文件“”,第 950 行
  _load_unlocked 中的文件“”,第 655 行
  文件“”,第 678 行,在 exec_module 中
  _call_with_frames_removed 中的文件“”,第 205 行
   中的文件“/Users/christos/store/store/urls.py”,第 18 行
    从 oscar.app 导入应用程序
   中的文件“/Users/christos/store-env/lib/python3.6/site-packages/oscar/app.py”,第 5 行
    从 django.contrib.auth 导入视图作为 auth_views
   中的文件“/Users/christos/store-env/lib/python3.6/site-packages/django/contrib/auth/views.py”,第 11 行
    从 django.contrib.auth.forms 导入(
   中的文件“/Users/christos/store-env/lib/python3.6/site-packages/django/contrib/auth/forms.py”,第 12 行
    从 django.contrib.auth.models 导入用户
   中的文件“/Users/christos/store-env/lib/python3.6/site-packages/django/contrib/auth/models.py”,第 6 行
    从 django.contrib.contenttypes.models 导入 ContentType
   中的文件“/Users/christos/store-env/lib/python3.6/site-packages/django/contrib/contenttypes/models.py”,第 138 行
    类内容类型(模型。模型):
  文件“/Users/christos/store-env/lib/python3.6/site-packages/django/db/models/base.py”,第 113 行,在 __new__
    “INSTALLED_APPS。” %(模块,名称)
RuntimeError:模型类 django.contrib.contenttypes.models.ContentType 未声明显式 app_label 并且不在 INSTALLED_APPS 中的应用程序中。
(store-env) ~/store $

我目前的settings.py,从据报道在 SO 上对其他人有用的内容进行了有益或无益的修改,直到未触及的import os

from oscar.defaults import *

from django.conf import settings

settings.configure()

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = '[DELETED]'

from oscar import get_core_apps

INSTALLED_APPS = [
    #'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'django.contrib.flatpages',
    'django.contrib.sites.models.Site',
    'django.contrib.contenttypes.models.ContentType',
    'compressor',
    'widget_tweaks'
] + get_core_apps()

import django
django.setup()
"""
Django settings for store project.

Generated by 'django-admin startproject' using Django 1.10.6.

For more information on this file, see
https://docs.djangoproject.com/en/1.10/topics/settings/

For the full list of settings and their values, see
https://docs.djangoproject.com/en/1.10/ref/settings/
"""

import os

我可以/应该怎么做才能让 Oscar 拥有它应该获得的所有应用程序?

【问题讨论】:

  • 您应该将应用添加到已安装的应用而不是模型,即django.contrib.sitesdjango.contrib.contenttypes
  • 谢谢;我已经删除了引用单个模型的行。错误信息是一样的。
  • 我看到我的问题被否决了。对于哪些更改可以使我的问题变得更好并且不那么值得投票,我可以提供任何建议吗?

标签: python django python-3.x django-apps django-oscar


【解决方案1】:
'django.contrib.sites.models.Site',
'django.contrib.contenttypes.models.ContentType'

这不应出现在已安装的应用部分。这些是模型,安装的应用程序部分主要用于应用程序。

【讨论】:

    猜你喜欢
    • 2010-10-08
    • 2011-07-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多