所以我有一个扩展的用户模型(扩展的AbstractUser)称为Profile。这是在一个名为“个人资料”的单独应用程序中。我正在插入标准登录名,并意识到它正在寻找一个“配置文件”应用程序名称作为标准,因此我将其重命名(目录、代码、数据库模式),我认为它应该可以工作。 app_name 实际上已经在 apps.py 中设置为“profile”,因此不需要重命名 url 引用。
没有骰子。我收到标题中的错误。
所以我删除了所有迁移(我仍然可以做到这一点:))并删除了我当前正在使用的 sqlite DB,认为我只需重新运行迁移并重新创建所有内容。
同样的错误。
堆栈跟踪是:
λ python manage.py makemigrations
Traceback (most recent call last):
File "manage.py", line 21, in <module>
main()
File "manage.py", line 17, in main
execute_from_command_line(sys.argv)
File "C:\Users\mjnic\.virtualenvs\pyp-E_0Se9Bl\lib\site-packages\django\core\management\__init__.py", line 381, in execute_from_command_line
utility.execute()
File "C:\Users\mjnic\.virtualenvs\pyp-E_0Se9Bl\lib\site-packages\django\core\management\__init__.py", line 375, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "C:\Users\mjnic\.virtualenvs\pyp-E_0Se9Bl\lib\site-packages\django\core\management\base.py", line 323, in run_from_argv
self.execute(*args, **cmd_options)
File "C:\Users\mjnic\.virtualenvs\pyp-E_0Se9Bl\lib\site-packages\django\core\management\base.py", line 361, in execute
self.check()
File "C:\Users\mjnic\.virtualenvs\pyp-E_0Se9Bl\lib\site-packages\django\core\management\base.py", line 390, in check
include_deployment_checks=include_deployment_checks,
File "C:\Users\mjnic\.virtualenvs\pyp-E_0Se9Bl\lib\site-packages\django\core\management\base.py", line 377, in _run_checks
return checks.run_checks(**kwargs)
File "C:\Users\mjnic\.virtualenvs\pyp-E_0Se9Bl\lib\site-packages\django\core\checks\registry.py", line 72, in run_checks
new_errors = check(app_configs=app_configs)
File "C:\Users\mjnic\.virtualenvs\pyp-E_0Se9Bl\lib\site-packages\debug_toolbar\apps.py", line 18, in check_middleware
from debug_toolbar.middleware import DebugToolbarMiddleware
File "C:\Users\mjnic\.virtualenvs\pyp-E_0Se9Bl\lib\site-packages\debug_toolbar\middleware.py", line 12, in <module>
from debug_toolbar.toolbar import DebugToolbar
File "C:\Users\mjnic\.virtualenvs\pyp-E_0Se9Bl\lib\site-packages\debug_toolbar\toolbar.py", line 141, in <module>
urlpatterns = DebugToolbar.get_urls()
File "C:\Users\mjnic\.virtualenvs\pyp-E_0Se9Bl\lib\site-packages\debug_toolbar\toolbar.py", line 134, in get_urls
for panel_class in cls.get_panel_classes():
File "C:\Users\mjnic\.virtualenvs\pyp-E_0Se9Bl\lib\site-packages\debug_toolbar\toolbar.py", line 116, in get_panel_classes
import_string(panel_path) for panel_path in dt_settings.get_panels()
File "C:\Users\mjnic\.virtualenvs\pyp-E_0Se9Bl\lib\site-packages\debug_toolbar\toolbar.py", line 116, in <listcomp>
import_string(panel_path) for panel_path in dt_settings.get_panels()
File "C:\Users\mjnic\.virtualenvs\pyp-E_0Se9Bl\lib\site-packages\django\utils\module_loading.py", line 17, in import_string
module = import_module(module_path)
File "C:\Users\mjnic\.virtualenvs\pyp-E_0Se9Bl\lib\importlib\__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "C:\Users\mjnic\.virtualenvs\pyp-E_0Se9Bl\lib\site-packages\debug_toolbar\panels\profiling.py", line 1, in <module>
import cProfile
File "D:\Python\Python37-32\Lib\cProfile.py", line 22, in <module>
run.__doc__ = _pyprofile.run.__doc__
AttributeError: module 'profile' has no attribute 'run'
此次重命名过程中我错过了什么?
我错过发布的任何其他有帮助的信息吗? (我已经搜索了“配置文件”的任何实例,但现在所有内容都已正确重命名,并且应用程序在此之前工作正常,因此纯粹是此重命名将其搞砸了)。
编辑:“配置文件”可能与某些内部Python例程冲突吗? python安装下的cProfile.py文件定义为
#! /usr/bin/env python3
"""Python interface for the 'lsprof' profiler.
Compatible with the 'profile' module.
"""
现在这和我的项目没有任何关系吗?我是否只需将我的应用程序/扩展用户模型称为“个人资料”之外的其他名称?
好的。所以是的,这是命名冲突。我已将我的“个人资料”模型和“个人资料”应用程序重命名为“UserProfile”和“user_profile”,并相应地更新了所有内容。现在一切似乎都有效......
只是在这里给出答案,以防将来有人遇到同样的问题!
就我而言,它是
profile.py
文件。
删除文件并重试。
在我的例子中,应用程序 - 'profile' 和 'django-debug-toolbar' 之间存在冲突:
我将我的应用程序从“个人资料”重命名为“帐户”,它解决了问题
对于那些在 Django 中拥有名为“profile”的应用程序并且还想在 Django shell 中使用 ipython 作为接口的人,我得到了一个有点棘手的解决方案。最近,我遇到了同样的问题,我只是潜入库中,更改了一行代码。
就我而言,我不需要在
requirement.txt
中将 ipython 提交为必需的库。所以我只是在本地修改代码。
回到错误,它说:
File "/some_path/.pyenv/versions/3.7.17/lib/python3.7/cProfile.py", line 22, in <module>
run.__doc__ = _pyprofile.run.__doc__
AttributeError: module 'profile' has no attribute 'run'
似乎它相对导入了错误
profile.py
(就我而言,我有一个名为profile
的应用程序)
我所做的就是转到那个
cProfile.py
,更改以下行:import profile as _pyprofile
from .profile import Profile as _pyprofile
问题解决了。
python版本:3.7.17
ipython版本:7.34.0