嗨,
我想在Visual Studio中使用Python 3.7和Django 2.1。我刚刚从VisualStudio创建了一个新的Django项目它创建了PythonDjango项目。
但是当我尝试从上的命令行运行'createsuperuser'命令时Visual Studio,我收到了这个长错误文本。
我的电脑上有Python 3.7和Django 2.1版本,所以我认为这与版本无关
我该如何解决这个问题?
Traceback (most recent call last):
File "c:usersmisafirsourcereposDjangoWebProject7DjangoWebProject7manage.py", line 17, in <module>
execute_from_command_line(sys.argv)
File "c:usersmisafirsourcereposDjangoWebProject7DjangoWebProject7envlibsite-packagesdjangocoremanagement__init__.py", line 381, in execute_from_command_line
utility.execute()
File "c:usersmisafirsourcereposDjangoWebProject7DjangoWebProject7envlibsite-packagesdjangocoremanagement__init__.py", line 375, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "c:usersmisafirsourcereposDjangoWebProject7DjangoWebProject7envlibsite-packagesdjangocoremanagementbase.py", line 316, in run_from_argv
self.execute(*args, **cmd_options)
File "c:usersmisafirsourcereposDjangoWebProject7DjangoWebProject7envlibsite-packagesdjangocontribauthmanagementcommandscreatesuperuser.py", line 59, in execute
return super().execute(*args, **options)
File "c:usersmisafirsourcereposDjangoWebProject7DjangoWebProject7envlibsite-packagesdjangocoremanagementbase.py", line 350, in execute
self.check()
File "c:usersmisafirsourcereposDjangoWebProject7DjangoWebProject7envlibsite-packagesdjangocoremanagementbase.py", line 379, in check
include_deployment_checks=include_deployment_checks,
File "c:usersmisafirsourcereposDjangoWebProject7DjangoWebProject7envlibsite-packagesdjangocoremanagementbase.py", line 366, in _run_checks
return checks.run_checks(**kwargs)
File "c:usersmisafirsourcereposDjangoWebProject7DjangoWebProject7envlibsite-packagesdjangocorechecksregistry.py", line 71, in run_checks
new_errors = check(app_configs=app_configs)
File "c:usersmisafirsourcereposDjangoWebProject7DjangoWebProject7envlibsite-packagesdjangocorechecksurls.py", line 13, in check_url_config
return check_resolver(resolver)
File "c:usersmisafirsourcereposDjangoWebProject7DjangoWebProject7envlibsite-packagesdjangocorechecksurls.py", line 23, in check_resolver
return check_method()
File "c:usersmisafirsourcereposDjangoWebProject7DjangoWebProject7envlibsite-packagesdjangourlsresolvers.py", line 396, in check
for pattern in self.url_patterns:
File "c:usersmisafirsourcereposDjangoWebProject7DjangoWebProject7envlibsite-packagesdjangoutilsfunctional.py", line 37, in __get__
res = instance.__dict__[self.name] = self.func(instance)
File "c:usersmisafirsourcereposDjangoWebProject7DjangoWebProject7envlibsite-packagesdjangourlsresolvers.py", line 533, in url_patterns
patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module)
File "c:usersmisafirsourcereposDjangoWebProject7DjangoWebProject7envlibsite-packagesdjangoutilsfunctional.py", line 37, in __get__
res = instance.__dict__[self.name] = self.func(instance)
File "c:usersmisafirsourcereposDjangoWebProject7DjangoWebProject7envlibsite-packagesdjangourlsresolvers.py", line 526, in urlconf_module
return import_module(self.urlconf_name)
File "C:Pythonlibimportlib__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 ".DjangoWebProject7urls.py", line 23, in <module>
django.contrib.auth.views.login,
AttributeError: module 'django.contrib.auth.views' has no attribute 'login'
django.contrib.auth.views.login
已在django 2.1中删除。来自发行说明:
contrib.auth.views.login((、logout((、password_change(。
您现在应该在URL中使用基于类的视图django.contrib.auth.views.LoginView
,例如最简单的形式:
path('login/', LoginView.as_view()),
模块'django.contrib.auth.views'没有属性'login'
错误清楚地显示。。。。我希望你正在使用身份验证模块,这就是你面对这个的原因
看起来您使用的是windows操作系统。从回溯错误中,我可以看出您没有正确安装django。试着为您创建的每个项目创建一个虚拟环境,并在那里安装django。这是开发人员的最佳实践。
这将清除你的问题,我希望如此。
干杯:(