嗨,
我想在Visual Studio中使用Python 3.7和Django 2.1。 我只是从 Visual Studio创建一个新的Django项目。。它创建了Python-Django项目。
但是当我尝试从命令行运行'createsuperuser'命令时 Visual Studio,我收到了这么长的错误文本。
我的计算机上有Python 3.7和Django 2.1版本,所以我认为这与该版本无关。
我该如何解决这个问题?
Traceback (most recent call last):
File "c:\users\misafir\source\repos\DjangoWebProject7\DjangoWebProject7\manage.py", line 17, in <module>
execute_from_command_line(sys.argv)
File "c:\users\misafir\source\repos\DjangoWebProject7\DjangoWebProject7\env\lib\site-packages\django\core\management\__init__.py", line 381, in execute_from_command_line
utility.execute()
File "c:\users\misafir\source\repos\DjangoWebProject7\DjangoWebProject7\env\lib\site-packages\django\core\management\__init__.py", line 375, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "c:\users\misafir\source\repos\DjangoWebProject7\DjangoWebProject7\env\lib\site-packages\django\core\management\base.py", line 316, in run_from_argv
self.execute(*args, **cmd_options)
File "c:\users\misafir\source\repos\DjangoWebProject7\DjangoWebProject7\env\lib\site-packages\django\contrib\auth\management\commands\createsuperuser.py", line 59, in execute
return super().execute(*args, **options)
File "c:\users\misafir\source\repos\DjangoWebProject7\DjangoWebProject7\env\lib\site-packages\django\core\management\base.py", line 350, in execute
self.check()
File "c:\users\misafir\source\repos\DjangoWebProject7\DjangoWebProject7\env\lib\site-packages\django\core\management\base.py", line 379, in check
include_deployment_checks=include_deployment_checks,
File "c:\users\misafir\source\repos\DjangoWebProject7\DjangoWebProject7\env\lib\site-packages\django\core\management\base.py", line 366, in _run_checks
return checks.run_checks(**kwargs)
File "c:\users\misafir\source\repos\DjangoWebProject7\DjangoWebProject7\env\lib\site-packages\django\core\checks\registry.py", line 71, in run_checks
new_errors = check(app_configs=app_configs)
File "c:\users\misafir\source\repos\DjangoWebProject7\DjangoWebProject7\env\lib\site-packages\django\core\checks\urls.py", line 13, in check_url_config
return check_resolver(resolver)
File "c:\users\misafir\source\repos\DjangoWebProject7\DjangoWebProject7\env\lib\site-packages\django\core\checks\urls.py", line 23, in check_resolver
return check_method()
File "c:\users\misafir\source\repos\DjangoWebProject7\DjangoWebProject7\env\lib\site-packages\django\urls\resolvers.py", line 396, in check
for pattern in self.url_patterns:
File "c:\users\misafir\source\repos\DjangoWebProject7\DjangoWebProject7\env\lib\site-packages\django\utils\functional.py", line 37, in __get__
res = instance.__dict__[self.name] = self.func(instance)
File "c:\users\misafir\source\repos\DjangoWebProject7\DjangoWebProject7\env\lib\site-packages\django\urls\resolvers.py", line 533, in url_patterns
patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module)
File "c:\users\misafir\source\repos\DjangoWebProject7\DjangoWebProject7\env\lib\site-packages\django\utils\functional.py", line 37, in __get__
res = instance.__dict__[self.name] = self.func(instance)
File "c:\users\misafir\source\repos\DjangoWebProject7\DjangoWebProject7\env\lib\site-packages\django\urls\resolvers.py", line 526, in urlconf_module
return import_module(self.urlconf_name)
File "C:\Python\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 ".\DjangoWebProject7\urls.py", line 23, in <module>
django.contrib.auth.views.login,
AttributeError: module 'django.contrib.auth.views' has no attribute 'login'
答案 0 :(得分:4)
django.contrib.auth.views.login
已在Django 2.1中删除。来自Release notes:
contrib.auth.views.login(),logout(),password_change(),password_change_done(),password_reset(),password_reset_done(),password_reset_confirm()和password_reset_complete()被删除。
您现在应该在网址中使用基于类的视图django.contrib.auth.views.LoginView
,例如最简单的形式:
path('login/', LoginView.as_view()),
答案 1 :(得分:0)
模块'django.contrib.auth.views'没有属性'登录'
该错误明确显示。 我希望您使用的是身份验证模块,为什么会遇到此问题
答案 2 :(得分:0)
在login
模块中没有名为 django.contrib.auth.views
的功能/属性。您可能正在尝试导入 login_required
。如果是这样,请尝试
from django.contrib.auth.views import login_required
答案 3 :(得分:-2)
您似乎正在使用Windows操作系统。从回溯错误中,我可以看到您没有正确安装django。尝试为您创建的每个项目创建一个虚拟环境,并在其中安装django。这是开发人员的最佳实践。
这将清除您希望的问题。
干杯:)