Search code examples
djangodjango-settings

creating django project just doesnt work right


i create a project folder, than create a venv and do $ django-admin startproject trydjango. now when i try to run runserver it gives me an error that it couldnt find manage.py, so i have to move it to the original project folder (which now has venv, trydjango, and manage.py). this is a problem i have seen online.

however, when i try to run runserver now it says:

"ModuleNotFoundError: No module named 'trydjango.settings'" 

(full traceback below)

the weird thing is, i have opened a project file just like this before, but now its not working. i have done it in the exact same way, the exact way that tutorials show. the only thing that changed is the django version - the tutorial said to use 2.0.7 in order to be able to follow the tutorial.

full traceback:

Traceback (most recent call last):
  File "E:\Python\projects\try_django_project\manage.py", line 15, in <module>
    execute_from_command_line(sys.argv)
  File "E:\Python\projects\try_django_project\venv\lib\site-packages\django\core\management\__init__.py", line 371, in execute_from_command_line
    utility.execute()
  File "E:\Python\projects\try_django_project\venv\lib\site-packages\django\core\management\__init__.py", line 317, in execute
    settings.INSTALLED_APPS
  File "E:\Python\projects\try_django_project\venv\lib\site-packages\django\conf\__init__.py", line 56, in __getattr__
    self._setup(name)
  File "E:\Python\projects\try_django_project\venv\lib\site-packages\django\conf\__init__.py", line 43, in _setup
    self._wrapped = Settings(settings_module)
  File "E:\Python\projects\try_django_project\venv\lib\site-packages\django\conf\__init__.py", line 106, in __init__
    mod = importlib.import_module(self.SETTINGS_MODULE)
  File "C:\Users\user\AppData\Local\Programs\Python\Python39\lib\importlib\__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1030, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1007, in _find_and_load
  File "<frozen importlib._bootstrap>", line 984, in _find_and_load_unlocked
ModuleNotFoundError: No module named 'trydjango.settings'

Solution

  • I will suggest you doing such way:

    1. Create a virtualenvironment named env or venv or as your wish and activate it.

    2. Then install django via pip install django

    3. now run this command django-admin startproject trydjango You can see you project structure such way:

      -env

      -trydjango

      --trydjango

      --manage.py

    4. Now enter the project directory where manage.py stays and run python manage.py runserver

    Hope this will work for you.