Django tutorial: `python manage.py startapp polls` fails

Trying the official tutorial, using Catalina 10.15.5, python 3.8.3 and django 3.0.6, is failing with:

TypeError: argument of type 'PosixPath' is not iterable

Absolute beginner with Django, couldn’t find much help with searches.

Where at within the official tutorial are you receiving this message?
(What command is generating this message and what step are you on?)

1 Like

From here, everything was successful until I got to this section.

The traceback is:
Traceback (most recent call last):

File “manage.py”, line 22, in
main()
File “manage.py”, line 18, in main
execute_from_command_line(sys.argv)
File “/Users/bobrien/.pyenv/versions/django-realpython.com/lib/python3.8/site-packages/django/core/management/init.py”, line 401, in execute_from_command_line
utility.execute()
File “/Users/bobrien/.pyenv/versions/django-realpython.com/lib/python3.8/site-packages/django/core/management/init.py”, line 395, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File “/Users/bobrien/.pyenv/versions/django-realpython.com/lib/python3.8/site-packages/django/core/management/base.py”, line 341, in run_from_argv
connections.close_all()
File “/Users/bobrien/.pyenv/versions/django-realpython.com/lib/python3.8/site-packages/django/db/utils.py”, line 230, in close_all
connection.close()
File “/Users/bobrien/.pyenv/versions/django-realpython.com/lib/python3.8/site-packages/django/utils/asyncio.py”, line 26, in inner
return func(*args, **kwargs)
File “/Users/bobrien/.pyenv/versions/django-realpython.com/lib/python3.8/site-packages/django/db/backends/sqlite3/base.py”, line 261, in close
if not self.is_in_memory_db():
File “/Users/bobrien/.pyenv/versions/django-realpython.com/lib/python3.8/site-packages/django/db/backends/sqlite3/base.py”, line 380, in is_in_memory_db
return self.creation.is_in_memory_db(self.settings_dict[‘NAME’])
File “/Users/bobrien/.pyenv/versions/django-realpython.com/lib/python3.8/site-packages/django/db/backends/sqlite3/creation.py”, line 12, in is_in_memory_db
return database_name == ‘:memory:’ or ‘mode=memory’ in database_name
TypeError: argument of type ‘PosixPath’ is not iterable

I think you’ve somehow used Django 3.1’s startproject template. Django 3.1 moved the BASE_DIR pseudo-setting to use pathlib.Path rather than a plain string. Support for this needed adding to some places like the sqlite driver, so it doesn’t work there.

If you look at the definition of BASE_DIR in your settings file, is it using a Path() ? If so you can use str() around its use in your DATABASES setting, i.e. str(BASE_DIR / "something.sqlite").

I covered this change more in a blog post: Use Pathlib in Your Django Settings File

Hope that helps

6 Likes

@adamchainz @KenWhitesell
Thank you both for your help.
I deactivated my virtualenv and got past this error.
Now, I’m into the actual polls app - and can see both /polls and /admin, but getting a 404 when I try to access http://127.0.0.1:8000 :joy:

Please note: I’m not asking for help on my new issue in this thread. I’ll open a new topic if I can’t figure this one out.

Again, thank you from a Django beginner!

2 Likes

@bryanmobrien that’s expected. There is no URL mapped at the root, only the index at polls/ and the admin at admin/, so you should see Django’s yellow debug 404 page when visiting the root URL.

Thank you! I assumed I fat-fingered urls.py or settings.
Moving forward! :crazy_face:

I had the same problem as the original poster and your solution worked! Thanks for your help

Thanks a lot. Your suggestion was really helpful to solve this problem I also ran into.

Your solution solve my problem thanks, but just I want to inform that this change need to be in the settings.py file
the path: /your_project/src/mysite