Closed Brzozova closed 3 years ago
Hmm ... for me (Python 3.8.9, Django 2.2.24) the mysite/settings.py
file generated by django-admin startproject mysite .
already has import os
.
Are you maybe using a different Version of Django, @Brzozova?
Yes, I use Django==3.1 and Python==3.8.10. Good catch.
Sooo I googled a little bit and found this solution: https://stackoverflow.com/questions/63436120/django-new-version-3-1-the-settings-file-have-some-changes
It tells it's not always required to import os module, but you can also change form of STATIC_ROOT.
Changing this: STATIC_ROOT = os.path.join(BASE_DIR, 'static')
To this: STATIC_ROOT = BASE_DIR / 'static'
Also, I found that import os is not by default for Django 3.1+ versions: https://docs.djangoproject.com/en/3.2/releases/3.1/#miscellaneous
Quote: "The settings.py generated by the startproject command now uses pathlib.Path instead of os.path for building filesystem paths."
What do you think about it? Should I add some kind of warning, that "if you use Django 3.1+ versions, remember to import os"?
What do you think about it? Should I add some kind of warning, that "if you use Django 3.1+ versions, remember to import os"?
The proper long-term solution is to upgrade the tutorial to Django 3.x, with all that entails. Some work towards that goal has been begun on branch django-3.1, mainly by @nikhiljohn10. Help there would be appreciated (both reviewing / testing, as well as completing the still-missing steps if any.)
What do you think about it? Should I add some kind of warning, that "if you use Django 3.1+ versions, remember to import os"?
The proper long-term solution is to upgrade the tutorial to Django 3.x, with all that entails. Some work towards that goal has been begun on branch django-3.1, mainly by @nikhiljohn10. Help there would be appreciated (both reviewing / testing, as well as completing the still-missing steps if any.)
Currently tutorial is using 2.2.4. In the migration to Django 3.1, this issue is resolved by adopting the new method from the pathlib module. This is the default for versions from 3.1 of Django. So once the updated files are reflected on the website, everything is going to be fine.
For now, people need to use the requirement.txt file with Django~=2.2.4
as directed in the tutorial.
Great, I already finished a blog with Django 3.1 using DjangoGirls tutorial and it was the only problem I found during this process. Also, I am eager to help with documentation development for Django 3.1.
To sum up, if you already created separate documentation for Django 3.1 and implemented pathlib module to fix it, then I suppose this PR can be closed.
Great, I already finished a blog with Django 3.1 using DjangoGirls tutorial and it was the only problem I found during this process. Also, I am eager to help with documentation development for Django 3.1.
You can find the migration PR at #1679 to contribute. There is an extended version of Django tutorial where many changes are not reflected I suppose. So all these bugs and enhancements are to be tracked and fixed.
To sum up, if you already created separate documentation for Django 3.1 and implemented pathlib module to fix it, then I suppose this PR can be closed.
pathlib module is adopted by Django since version 3.1. So I suppose you can close this PR as it is clear that importing os
module will not be a suggested way to refer paths in future.
Without importing os module, database creation with python manage.py migrate command will crush with error: