ModuleNotFoundError: No module named ‘XXX‘; ‘XXX‘ is not a package问题

1 The honey bug I encountered today when using pycharm to run the django project.

My detailed error here is: ModuleNotFoundError: No module named 'django.contrib.auth.middleware.py'; 'django.contrib.auth.middleware' is not a package

Seeing middleware.py, I remembered that when I renamed the middleware.py created by the component a while ago, the following prompt appeared in pycharm:

The refactoring I performed directly at that time caused the data of many files to change, such as MIDDLEWARE in setting.py:

#正常情况

'django.middleware.csrf.CsrfViewMiddleware',

#重构后

'django.middleware.py.csrf.CsrfViewMiddleware',

This is my reason for the "module not found" error.

solution:

I am reporting an error here because the middleware field of the configuration file has been reconstructed into middleware.py, so I renamed the file (my middleware.py here) to middleware, and then you will see the property refactoring reminder interface:

Click Execute Refactoring below, and find that the affected line in MIDDLEWARE in setting.py has changed (the refactored files are different, and the affected fields will be different).

Run it again and find that the operation is successful, and the problem is solved.

Hope to help you ^_^

 

Guess you like

Origin blog.csdn.net/qq_58174484/article/details/125420765