我已经开始学习Django,但无法运行服务器。
Python和PyCharm已重新安装,我已经通过命令pip install Django
安装了Django。之后,当我运行命令python manage.py runserver
时,出现错误:
没有这样的文件和目录
所以我复制了manage.py
文件,然后将其粘贴到所写的路径下,当我再次键入时,它显示了这个奇怪的长错误,我尝试了所有路径,但它给我的错误是没有这样的文件并且目录只在一个路径上,这给了我一个奇怪的长错误,是
(venv) C:\Users\Usman Raees\PycharmProjects\pyshop>python manage.py runserver
Traceback (most recent call last):
File "C:\Users\Usman Raees\PycharmProjects\pyshop\venv\lib\site-packages\django\core\management\base.py", line 330, in run_from_argv
self.execute(*args, **cmd_options)
File "C:\Users\Usman Raees\PycharmProjects\pyshop\venv\lib\site-packages\django\core\management\commands\runserver.py", line 61, in execute
super().execute(*args, **options)
File "C:\Users\Usman Raees\PycharmProjects\pyshop\venv\lib\site-packages\django\core\management\base.py", line 371, in execute
output = self.handle(*args, **options)
File "C:\Users\Usman Raees\PycharmProjects\pyshop\venv\lib\site-packages\django\core\management\commands\runserver.py", line 68, in handle
if not settings.DEBUG and not settings.ALLOWED_HOSTS:
File "C:\Users\Usman Raees\PycharmProjects\pyshop\venv\lib\site-packages\django\conf\__init__.py", line 83, in __getattr__
self._setup(name)
File "C:\Users\Usman Raees\PycharmProjects\pyshop\venv\lib\site-packages\django\conf\__init__.py", line 70, in _setup
self._wrapped = Settings(settings_module)
File "C:\Users\Usman Raees\PycharmProjects\pyshop\venv\lib\site-packages\django\conf\__init__.py", line 177, in __init__
mod = importlib.import_module(self.SETTINGS_MODULE)
File "C:\Users\Usman Raees\AppData\Local\Programs\Python\Python38\lib\importlib\__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1014, in _gcd_import
File "<frozen importlib._bootstrap>", line 991, in _find_and_load
File "<frozen importlib._bootstrap>", line 973, in _find_and_load_unlocked
ModuleNotFoundError: No module named 'pyshop.settings'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "manage.py", line 22, in <module>
main()
File "manage.py", line 18, in main
execute_from_command_line(sys.argv)
File "C:\Users\Usman Raees\PycharmProjects\pyshop\venv\lib\site-packages\django\core\management\__init__.py", line 401, in execute_from_command_line
utility.execute()
File "C:\Users\Usman Raees\PycharmProjects\pyshop\venv\lib\site-packages\django\core\management\__init__.py", line 395, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "C:\Users\Usman Raees\PycharmProjects\pyshop\venv\lib\site-packages\django\core\management\base.py", line 343, in run_from_argv
connections.close_all()
File "C:\Users\Usman Raees\PycharmProjects\pyshop\venv\lib\site-packages\django\db\utils.py", line 232, in close_all
for alias in self:
File "C:\Users\Usman Raees\PycharmProjects\pyshop\venv\lib\site-packages\django\db\utils.py", line 226, in __iter__
return iter(self.databases)
File "C:\Users\Usman Raees\PycharmProjects\pyshop\venv\lib\site-packages\django\utils\functional.py", line 48, in __get__
res = instance.__dict__[self.name] = self.func(instance)
File "C:\Users\Usman Raees\PycharmProjects\pyshop\venv\lib\site-packages\django\db\utils.py", line 153, in databases
self._databases = settings.DATABASES
File "C:\Users\Usman Raees\PycharmProjects\pyshop\venv\lib\site-packages\django\conf\__init__.py", line 83, in __getattr__
self._setup(name)
File "C:\Users\Usman Raees\PycharmProjects\pyshop\venv\lib\site-packages\django\conf\__init__.py", line 70, in _setup
self._wrapped = Settings(settings_module)
File "C:\Users\Usman Raees\PycharmProjects\pyshop\venv\lib\site-packages\django\conf\__init__.py", line 177, in __init__
mod = importlib.import_module(self.SETTINGS_MODULE)
File "C:\Users\Usman Raees\AppData\Local\Programs\Python\Python38\lib\importlib\__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1014, in _gcd_import
File "<frozen importlib._bootstrap>", line 991, in _find_and_load
File "<frozen importlib._bootstrap>", line 973, in _find_and_load_unlocked
ModuleNotFoundError: No module named 'pyshop.settings'
(venv) C:\Users\Usman Raees\PycharmProjects\pyshop>
答案 0 :(得分:0)
由于您刚刚开始学习。在python(pycharm专业版)中创建一个新的Django项目,然后再次启动该应用程序,请勿在任何地方复制manage.py文件。 还要运行
$ django-admin.py startproject Yourprojectname
在运行
之前python manage.py runserver