Manage
In [1]:
Copied!
"""Django's command-line utility for administrative tasks."""
import os
import sys
"""Django's command-line utility for administrative tasks."""
import os
import sys
In [2]:
Copied!
def main():
"""Run administrative tasks."""
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'project.settings')
try:
from django.core.management import execute_from_command_line
except ImportError as exc:
raise ImportError(
"Couldn't import Django. Are you sure it's installed and "
"available on your PYTHONPATH environment variable? Did you "
"forget to activate a virtual environment?"
) from exc
execute_from_command_line(sys.argv)
def main():
"""Run administrative tasks."""
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'project.settings')
try:
from django.core.management import execute_from_command_line
except ImportError as exc:
raise ImportError(
"Couldn't import Django. Are you sure it's installed and "
"available on your PYTHONPATH environment variable? Did you "
"forget to activate a virtual environment?"
) from exc
execute_from_command_line(sys.argv)
In [3]:
Copied!
if __name__ == '__main__':
main()
if __name__ == '__main__':
main()
--------------------------------------------------------------------------- KeyError Traceback (most recent call last) File c:\Users\00661711722\Documents\PBE_24.2_8002\.venv\Lib\site-packages\django\core\management\__init__.py:255, in ManagementUtility.fetch_command(self, subcommand) 254 try: --> 255 app_name = commands[subcommand] 256 except KeyError: KeyError: '-f' During handling of the above exception, another exception occurred: ModuleNotFoundError Traceback (most recent call last) Cell In[3], line 2 1 if __name__ == '__main__': ----> 2 main() Cell In[2], line 12, in main() 6 except ImportError as exc: 7 raise ImportError( 8 "Couldn't import Django. Are you sure it's installed and " 9 "available on your PYTHONPATH environment variable? Did you " 10 "forget to activate a virtual environment?" 11 ) from exc ---> 12 execute_from_command_line(sys.argv) File c:\Users\00661711722\Documents\PBE_24.2_8002\.venv\Lib\site-packages\django\core\management\__init__.py:442, in execute_from_command_line(argv) 440 """Run a ManagementUtility.""" 441 utility = ManagementUtility(argv) --> 442 utility.execute() File c:\Users\00661711722\Documents\PBE_24.2_8002\.venv\Lib\site-packages\django\core\management\__init__.py:436, in ManagementUtility.execute(self) 434 sys.stdout.write(self.main_help_text() + "\n") 435 else: --> 436 self.fetch_command(subcommand).run_from_argv(self.argv) File c:\Users\00661711722\Documents\PBE_24.2_8002\.venv\Lib\site-packages\django\core\management\__init__.py:262, in ManagementUtility.fetch_command(self, subcommand) 256 except KeyError: 257 if os.environ.get("DJANGO_SETTINGS_MODULE"): 258 # If `subcommand` is missing due to misconfigured settings, the 259 # following line will retrigger an ImproperlyConfigured exception 260 # (get_commands() swallows the original one) so the user is 261 # informed about it. --> 262 settings.INSTALLED_APPS 263 elif not settings.configured: 264 sys.stderr.write("No Django settings specified.\n") File c:\Users\00661711722\Documents\PBE_24.2_8002\.venv\Lib\site-packages\django\conf\__init__.py:81, in LazySettings.__getattr__(self, name) 79 """Return the value of a setting and cache it in self.__dict__.""" 80 if (_wrapped := self._wrapped) is empty: ---> 81 self._setup(name) 82 _wrapped = self._wrapped 83 val = getattr(_wrapped, name) File c:\Users\00661711722\Documents\PBE_24.2_8002\.venv\Lib\site-packages\django\conf\__init__.py:68, in LazySettings._setup(self, name) 60 desc = ("setting %s" % name) if name else "settings" 61 raise ImproperlyConfigured( 62 "Requested %s, but settings are not configured. " 63 "You must either define the environment variable %s " 64 "or call settings.configure() before accessing settings." 65 % (desc, ENVIRONMENT_VARIABLE) 66 ) ---> 68 self._wrapped = Settings(settings_module) File c:\Users\00661711722\Documents\PBE_24.2_8002\.venv\Lib\site-packages\django\conf\__init__.py:166, in Settings.__init__(self, settings_module) 163 # store the settings module in case someone later cares 164 self.SETTINGS_MODULE = settings_module --> 166 mod = importlib.import_module(self.SETTINGS_MODULE) 168 tuple_settings = ( 169 "ALLOWED_HOSTS", 170 "INSTALLED_APPS", (...) 173 "SECRET_KEY_FALLBACKS", 174 ) 175 self._explicit_settings = set() File C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.12_3.12.2032.0_x64__qbz5n2kfra8p0\Lib\importlib\__init__.py:90, in import_module(name, package) 88 break 89 level += 1 ---> 90 return _bootstrap._gcd_import(name[level:], package, level) File <frozen importlib._bootstrap>:1387, in _gcd_import(name, package, level) File <frozen importlib._bootstrap>:1360, in _find_and_load(name, import_) File <frozen importlib._bootstrap>:1310, in _find_and_load_unlocked(name, import_) File <frozen importlib._bootstrap>:488, in _call_with_frames_removed(f, *args, **kwds) File <frozen importlib._bootstrap>:1387, in _gcd_import(name, package, level) File <frozen importlib._bootstrap>:1360, in _find_and_load(name, import_) File <frozen importlib._bootstrap>:1324, in _find_and_load_unlocked(name, import_) ModuleNotFoundError: No module named 'project'