I got an unfamiliar error in Django: TypeError: resolve () got an unexpected keyword argument'strict'

Introduction

In the process of deploying the created Django app to AWS EC2 (Ubuntu16.04), I encountered the following error, so I will write down the remedy.

Details of the error

After git clone the Django project in Ubuntu, I ran python3 manage.py make migrations

TypeError: resolve() got an unexpected keyword argument 'strict'

Error was displayed.

settings.py


# Build paths inside the project like this: BASE_DIR / 'subdir'.
BASE_DIR = Path(__file__).resolve(strict=True).parent.parent

It seems that one sentence of is an error. This is the description to get the absolute path of the base directory where Django manage.py is located.

I wondered why this was because I don't remember messing around with it, and found that the description of this part changed between Django 3.1 and later and before that.

This time I was developing locally with Python 3.8 + Django 3.1, but when I confirmed it, Python 3.5 + Django 2.2 is installed on Ubuntu, and it seems that there is an error due to the difference in version.

The strict argument of the resolve method seems to have been added since python3.6, so this is probably the root cause.

Solution

Originally, it was necessary to develop according to the version of Django in Ubuntu, but this time I just wanted to easily try to deploy it, so I will change settings.py to the description according to Django 2.2.

settings.py


#This is Django 3.1 or later
# from pathlib import Path
# BASE_DIR = Path(__file__).resolve(strict=True).parent.parent

#Traditional description
import os
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))

By doing this, the error was successfully resolved and the migration was successful.

I think language and framework version control is especially important in development, so I'd like to be careful in the future.

reference

Recommended Posts

I got an unfamiliar error in Django: TypeError: resolve () got an unexpected keyword argument'strict'
Resolve TensorFlow TypeError: __init __ () got an unexpected keyword argument'syntax' on Mac
I got an error in vim and zsh in Python 3.7 series
TypeError: __init__ () got an unexpected keyword argument What to do with'status'
TypeError: concat () got an unexpected keyword argument'join_axes' when using pandas_profling (Google Colab)
I got an error when trying to run Hello World in Go language
I want to get an error message in Japanese with django Password Change Form
I got an error that Python couldn't read settings.ini
I get an Import Error in Python Beautiful Soup
I get an error when I put opencv in pyautoGUI
I got an error when using Tensorboard with Pytorch
I got an AttributeError when mocking the open method in python
I got an error when I ran composer global require laravel / installer
When I get an error with Pylint in Atom on Windows
I got an error when I ran meteor add accounts-password and got hooked
What to do if PyInstaller3.5 gives an error in Python3.8 (TypeError: an integer is required (got type bytes))