Django python manage.py runserverとpython manage.py createsuperuserをしたときのエラー解決方法
解決したいこと
ここに解決したい内容を記載してください。
例)
はじめてのDjangoアプリ作成のチュートリアルを進めいてる最中に以下の部分でエラーを吐いてしまいました。
入力したコマンド
python manage.py runserver
発生している問題・エラー
Watching for file changes with StatReloader
Exception in thread django-main-thread:
Traceback (most recent call last):
File "C:\Users\kieny\AppData\Local\Programs\Python\Python310\lib\threading.py", line 1016, in _bootstrap_inner
self.run()
File "C:\Users\kieny\AppData\Local\Programs\Python\Python310\lib\threading.py", line 953, in run
self._target(*self._args, **self._kwargs)
File "C:\Users\kieny\AppData\Local\Programs\Python\Python310\lib\site-packages\django\utils\autoreload.py", line 64, in wrapper
fn(*args, **kwargs)
File "C:\Users\kieny\AppData\Local\Programs\Python\Python310\lib\site-packages\django\core\management\commands\runserver.py", line 125, in inner_run
autoreload.raise_last_exception()
File "C:\Users\kieny\AppData\Local\Programs\Python\Python310\lib\site-packages\django\utils\autoreload.py", line 87, in raise_last_exception
raise _exception[1]
File "C:\Users\kieny\AppData\Local\Programs\Python\Python310\lib\site-packages\django\core\management\__init__.py", line 398, in execute
autoreload.check_errors(django.setup)()
File "C:\Users\kieny\AppData\Local\Programs\Python\Python310\lib\site-packages\django\utils\autoreload.py", line 64, in wrapper
fn(*args, **kwargs)
File "C:\Users\kieny\AppData\Local\Programs\Python\Python310\lib\site-packages\django\__init__.py", line 24, in setup
apps.populate(settings.INSTALLED_APPS)
File "C:\Users\kieny\AppData\Local\Programs\Python\Python310\lib\site-packages\django\apps\registry.py", line 116, in populate
app_config.import_models()
File "C:\Users\kieny\AppData\Local\Programs\Python\Python310\lib\site-packages\django\apps\config.py", line 269, in import_models
self.models_module = import_module(models_module_name)
File "C:\Users\kieny\AppData\Local\Programs\Python\Python310\lib\importlib\__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1050, in _gcd_import
File "<frozen importlib._bootstrap>", line 1027, in _find_and_load
File "<frozen importlib._bootstrap>", line 1006, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 688, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 879, in exec_module
File "<frozen importlib._bootstrap_external>", line 1017, in get_code
File "<frozen importlib._bootstrap_external>", line 947, in source_to_code
File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
File "C:\Users\kieny\mysite\polls\models.py", line 9
retrun self.question_text
^^^^
SyntaxError: invalid syntax
自分で試したこと
・pythonのバージョンを調べたところ、Python 3.10.6でした。
・Djangoのチュートリアル2(https://docs.djangoproject.com/ja/2.2/intro/tutorial02/)
「管理ユーザーを作成する」の段階で、下記のコマンドを打ったところ、うまくいかず、とりあえず再起動したところからサーバーも起動できなくなりました。
・その前にも「APIで遊んでみる」の段階で若干うまくいかなかったところがあったのでもしかしたらそこも関係あるのかもしれません。
入力したコマンド
python manage.py createsuperuser
発生している問題・エラー
Traceback (most recent call last):
File "C:\Users\kieny\mysite\manage.py", line 22, in <module>
main()
File "C:\Users\kieny\mysite\manage.py", line 18, in main
execute_from_command_line(sys.argv)
File "C:\Users\kieny\AppData\Local\Programs\Python\Python310\lib\site-packages\django\core\management\__init__.py", line 446, in execute_from_command_line
utility.execute()
File "C:\Users\kieny\AppData\Local\Programs\Python\Python310\lib\site-packages\django\core\management\__init__.py", line 420, in execute
django.setup()
File "C:\Users\kieny\AppData\Local\Programs\Python\Python310\lib\site-packages\django\__init__.py", line 24, in setup
apps.populate(settings.INSTALLED_APPS)
File "C:\Users\kieny\AppData\Local\Programs\Python\Python310\lib\site-packages\django\apps\registry.py", line 116, in populate
app_config.import_models()
File "C:\Users\kieny\AppData\Local\Programs\Python\Python310\lib\site-packages\django\apps\config.py", line 269, in import_models
self.models_module = import_module(models_module_name)
File "C:\Users\kieny\AppData\Local\Programs\Python\Python310\lib\importlib\__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1050, in _gcd_import
File "<frozen importlib._bootstrap>", line 1027, in _find_and_load
File "<frozen importlib._bootstrap>", line 1006, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 688, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 879, in exec_module
File "<frozen importlib._bootstrap_external>", line 1017, in get_code
File "<frozen importlib._bootstrap_external>", line 947, in source_to_code
File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
File "C:\Users\kieny\mysite\polls\models.py", line 9
retrun self.question_text
^^^^
SyntaxError: invalid syntax
0