# django tutorial

**URL:** <https://forum.djangoproject.com/t/django-tutorial/21809>\
**Category:** Getting Started\
**Created:** [June 23, 2023, 4:00pm UTC](https://forum.djangoproject.com/t/django-tutorial/21809 "2023-06-23T16:00:12Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![serrajo](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/serrajo/32/14404_2.png) [@serrajo](https://forum.djangoproject.com/u/serrajo)\
**Post date:** [June 23, 2023, 4:00pm UTC](https://forum.djangoproject.com/t/django-tutorial/21809/1 "2023-06-23T16:00:12Z")

</div>

Hi all, I have 2 questions:

1. is there a gitlab repository with the codes for the official django tutorial?
2. linked to question 1: I have arrived to the 5th section of the tutorial (about testing) and I think I have used exactly the same codes shown, with exact same folder structure.  
However, when running `python manage.py test polls` I get the following:

```auto
ERROR: mysite.polls (unittest.loader._FailedTest)
----------------------------------------------------------------------
ImportError: Failed to import test module: mysite.polls
Traceback (most recent call last):
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/unittest/loader.py", line 470, in _find_test_path
    package = self._get_module_from_name(name)
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/unittest/loader.py", line 377, in _get_module_from_name
    __import__ (name)
ModuleNotFoundError: No module named 'mysite.polls'

```

anybody had a similar issue?  
Thanks a lot

---

<div class="post-metadata">

**Author:** ![KenWhitesell](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/kenwhitesell/32/280_2.png) [@KenWhitesell](https://forum.djangoproject.com/u/KenWhitesell)\
**Post date:** [June 24, 2023, 12:46am UTC](https://forum.djangoproject.com/t/django-tutorial/21809/2 "2023-06-24T00:46:58Z")

</div>

Generally speaking, these types of errors are frequently caused by something missed or mistyped.

Which step are you at in the tutorial?

Please post a complete description of the directory structure of your project, along with your `INSTALLED_APPS` setting and the `apps.py` file in your polls app.  
(Copy/paste the contents - don’t post images or retype it.)

---

<div class="post-metadata">

**Author:** ![serrajo](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/serrajo/32/14404_2.png) [@serrajo](https://forum.djangoproject.com/u/serrajo)\
**Post date:** [June 26, 2023, 7:34am UTC](https://forum.djangoproject.com/t/django-tutorial/21809/3 "2023-06-26T07:34:38Z")

</div>

> [@KenWhitesell](#):
>
> complete description of the directory structure of your project

Hi, thanks for the reply. I am in step 5 (testing your application). My project directory structure is the following:

```auto
DjangoProject/
    main.py
    mysite/
        db.sqlite3
        __init__.py
        manage.py
        mysite/
            asgi.py
            __init__.py
            settings.py
            urls.py
            wsgi.py
        polls/
            models.py
            __init__.py
            apps.py
            admin.py
            tests.py
            urls.py
            views.py
            migrations/
                __init__.py
                0001_initial.py
            templates/
                polls/
                    index.html
                    results.html
                    detail.html

```

My INSTALLED\_APPS are the following:

```auto
INSTALLED_APPS = [
    'polls.apps.PollsConfig',
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
]

```

The content of the apps.py file is the following:

```auto
from django.apps import AppConfig
class PollsConfig(AppConfig):
    default_auto_field = 'django.db.models.BigAutoField'
    name = 'polls'

```

I also add that all the rest of the app works correctly, the only issue I am having is with this testing section.

---

<div class="post-metadata">

**Author:** ![KenWhitesell](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/kenwhitesell/32/280_2.png) [@KenWhitesell](https://forum.djangoproject.com/u/KenWhitesell)\
**Post date:** [June 26, 2023, 10:20am UTC](https://forum.djangoproject.com/t/django-tutorial/21809/4 "2023-06-26T10:20:20Z")

</div>

This all looks good. Please post the contents of your tests.py file.

---

<div class="post-metadata">

**Author:** ![serrajo](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/serrajo/32/14404_2.png) [@serrajo](https://forum.djangoproject.com/u/serrajo)\
**Post date:** [June 26, 2023, 10:32am UTC](https://forum.djangoproject.com/t/django-tutorial/21809/5 "2023-06-26T10:32:25Z")

</div>

> [@KenWhitesell](#):
>
> contents

here it is

```auto
import datetime

from django.test import TestCase
from django.utils import timezone

from .models import Question

class QuestionModelTests(TestCase):

    def test_was_published_recently_with_future_question(self):
        """
        was_published_recently() returns False for questions whose pub_date
        is in the future.
        """
        time = timezone.now() + datetime.timedelta(days=30)
        future_question = Question(pub_date=time)
        self.assertIs(future_question.was_published_recently(), False)

```

thanks for the help

---

<div class="post-metadata">

**Author:** ![KenWhitesell](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/kenwhitesell/32/280_2.png) [@KenWhitesell](https://forum.djangoproject.com/u/KenWhitesell)\
**Post date:** [June 26, 2023, 10:55am UTC](https://forum.djangoproject.com/t/django-tutorial/21809/6 "2023-06-26T10:55:27Z")

</div>

I’m a little curious about your directory structure - what is this “main.py” file? And why do you have an ` __init__.py` file in your project’s base directory? (Is it an empty file?)

In the tutorial, your “outer” `mysite` directory would be the project root, and it would be the current directory when you run manage.py. Is that the directory you are running this from?

---

<div class="post-metadata">

**Author:** ![serrajo](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/serrajo/32/14404_2.png) [@serrajo](https://forum.djangoproject.com/u/serrajo)\
**Post date:** [June 26, 2023, 11:01am UTC](https://forum.djangoproject.com/t/django-tutorial/21809/7 "2023-06-26T11:01:12Z")

</div>

> [@KenWhitesell](#):
>
> I’m a little curious about your directory structure - what is this “main.py” file? And why do you have an ` __init__.py` file in your project’s base directory? (Is it an empty file?)

The `main.py` file has this inside, Django or Pycharm created it by itself.

```auto

# This is a sample Python script.

# Press ⇧F10 to execute it or replace it with your code.
# Press Double ⇧ to search everywhere for classes, files, tool windows, actions, and settings.

def print_hi(name):
    # Use a breakpoint in the code line below to debug your script.
    print(f'Hi, {name}') # Press ⌘F8 to toggle the breakpoint.

# Press the green button in the gutter to run the script.
if __name__ == ' __main__':
    print_hi('PyCharm')

# See PyCharm help at https://www.jetbrains.com/help/pycharm/

```

The ` __init__.py` file is created automatically by pycharm, with nothing inside.

I think the tutorial intentionally thought there was an outer folder as it says:  
" From the command line, `cd` into a directory where you’d like to store your code, then run the following command"… This will create a `mysite` directory in your current directory. So the “Current directory” is the DjangoProject, then I cd to mysite, also following the tutorial, where it says:  
“Let’s verify your Django project works. Change into the outer `mysite` directory, if you haven’t already, and run the following commands:”

---

<div class="post-metadata">

**Author:** ![KenWhitesell](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/kenwhitesell/32/280_2.png) [@KenWhitesell](https://forum.djangoproject.com/u/KenWhitesell)\
**Post date:** [June 26, 2023, 11:06am UTC](https://forum.djangoproject.com/t/django-tutorial/21809/8 "2023-06-26T11:06:26Z")

</div>

Yes, but that outer directory (`DjangoProject`) is not part of your project. It would only be a container for all the projects that you might create using Django. The top-most (outermost) directory of your project is the first `mysite` directory. There should not be an ` __init__.py` file in that directory.

So try removing that file, make sure that the outer `mysite` directory is your current directory, and try running the `manage.py` command again.

---

<div class="post-metadata">

**Author:** ![serrajo](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/serrajo/32/14404_2.png) [@serrajo](https://forum.djangoproject.com/u/serrajo)\
**Post date:** [June 26, 2023, 12:33pm UTC](https://forum.djangoproject.com/t/django-tutorial/21809/9 "2023-06-26T12:33:20Z")

</div>

great it seems it works now, wouldn’t have thought about it  
thanks
