Decided to take out Django 2.2 for a spin (project is currently running 2.1.8) and now I can't even get the server to start. I have been maintaining this project for nearly two years and this should be a minor update.
The error seems to be related to my views, but I can't find anything in the release notes that has meaningfully changed between 2.1.8 and 2.2. I suspect it may be due to my rather non-standard view
system. Instead of a single file called views.py
, I use a folder of view
files joined by an __init__.py
. But again, that's just a guess.
Watching for file changes with StatReloader
Exception in thread Thread-1:
Traceback (most recent call last):
File "C:\Python37\lib\threading.py", line 917, in _bootstrap_inner
self.run()
File "C:\Python37\lib\threading.py", line 865, in run
self._target(*self._args, **self._kwargs)
File "C:\Python37\lib\site-packages\django\utils\autoreload.py", line 54, in wrapper
fn(*args, **kwargs)
File "C:\Python37\lib\site-packages\django\core\management\commands\runserver.py", line 117, in inner_run
self.check(display_num_errors=True)
File "C:\Python37\lib\site-packages\django\core\management\base.py", line 390, in check
include_deployment_checks=include_deployment_checks,
File "C:\Python37\lib\site-packages\django\core\management\base.py", line 377, in _run_checks
return checks.run_checks(**kwargs)
File "C:\Python37\lib\site-packages\django\core\checks\registry.py", line 72, in run_checks
new_errors = check(app_configs=app_configs)
File "C:\Python37\lib\site-packages\django\core\checks\urls.py", line 13, in check_url_config
return check_resolver(resolver)
File "C:\Python37\lib\site-packages\django\core\checks\urls.py", line 23, in check_resolver
return check_method()
File "C:\Python37\lib\site-packages\django\urls\resolvers.py", line 399, in check
messages.extend(check_resolver(pattern))
File "C:\Python37\lib\site-packages\django\core\checks\urls.py", line 23, in check_resolver
return check_method()
File "C:\Python37\lib\site-packages\django\urls\resolvers.py", line 400, in check
messages.extend(self._check_custom_error_handlers())
File "C:\Python37\lib\site-packages\django\urls\resolvers.py", line 408, in _check_custom_error_handlers
handler, param_dict = self.resolve_error_handler(status_code)
File "C:\Python37\lib\site-packages\django\urls\resolvers.py", line 590, in resolve_error_handler
return get_callable(callback), {}
File "C:\Python37\lib\site-packages\django\urls\utils.py", line 28, in get_callable
mod = import_module(mod_name)
File "C:\Python37\lib\importlib\__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1006, in _gcd_import
File "<frozen importlib._bootstrap>", line 983, in _find_and_load
File "<frozen importlib._bootstrap>", line 965, in _find_and_load_unlocked
ModuleNotFoundError: No module named 'views'
Traceback (most recent call last):
File "C:/git/si-dash/manage.py", line 22, in <module>
execute_from_command_line(sys.argv)
File "C:\Python37\lib\site-packages\django\core\management\__init__.py", line 381, in execute_from_command_line
utility.execute()
File "C:\Python37\lib\site-packages\django\core\management\__init__.py", line 375, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "C:\Python37\lib\site-packages\django\core\management\base.py", line 323, in run_from_argv
self.execute(*args, **cmd_options)
File "C:\Python37\lib\site-packages\django\core\management\commands\runserver.py", line 60, in execute
super().execute(*args, **options)
File "C:\Python37\lib\site-packages\django\core\management\base.py", line 364, in execute
output = self.handle(*args, **options)
File "C:\Python37\lib\site-packages\django\core\management\commands\runserver.py", line 95, in handle
self.run(**options)
File "C:\Python37\lib\site-packages\django\core\management\commands\runserver.py", line 102, in run
autoreload.run_with_reloader(self.inner_run, **options)
File "C:\Python37\lib\site-packages\django\utils\autoreload.py", line 579, in run_with_reloader
start_django(reloader, main_func, *args, **kwargs)
File "C:\Python37\lib\site-packages\django\utils\autoreload.py", line 564, in start_django
reloader.run(django_main_thread)
File "C:\Python37\lib\site-packages\django\utils\autoreload.py", line 275, in run
self.run_loop()
File "C:\Python37\lib\site-packages\django\utils\autoreload.py", line 281, in run_loop
next(ticker)
File "C:\Python37\lib\site-packages\django\utils\autoreload.py", line 321, in tick
state.update(self.loop_files(state, previous_timestamp))
File "C:\Python37\lib\site-packages\django\utils\autoreload.py", line 328, in loop_files
for path, mtime in self.snapshot_files():
File "C:\Python37\lib\site-packages\django\utils\autoreload.py", line 348, in snapshot_files
for file in self.watched_files():
File "C:\Python37\lib\site-packages\django\utils\autoreload.py", line 241, in watched_files
yield from iter_all_python_module_files()
File "C:\Python37\lib\site-packages\django\utils\autoreload.py", line 103, in iter_all_python_module_files
return iter_modules_and_files(modules, frozenset(_error_files))
File "C:\Python37\lib\site-packages\django\utils\autoreload.py", line 128, in iter_modules_and_files
if not path.exists():
File "C:\Python37\lib\pathlib.py", line 1339, in exists
self.stat()
File "C:\Python37\lib\pathlib.py", line 1161, in stat
return self._accessor.stat(self)
OSError: [WinError 123] The filename, directory name, or volume label syntax is incorrect: '<frozen importlib._bootstrap>'
Again, this view layout has been working for years now and I can't find anything relating to urls
or views
that has changed between 2.1.8 and 2.2.
All I am going off of is the sudden ModuleNotFoundError: No module named 'views'
Edit:
With @Alasdair 's help I have gotten past this error, but I still have no idea why this is going on. The project runs perfectly on 2.1.8, and there is nothing in the docs regarding a change in how you reference handler###
views. Also the fact that I got LookupError: No installed app with label 'admin'
and then that magically went away after uninstalling and installing 2.2 again doesn't make me feel great.
The first thing we need to understand is how URLs and Views work together in Django. When a web request is made to a Django application, it is the job of the urls.py file to determine what to do with that request. This is what is known as routing in a web application.
The views.py file is where you can define your view functions. These functions are what determine what the application does based on the URL that a user visits in a web browser. This is a similar concept to web application frameworks in any other language as well. Django’s approach is both elegant and easy to use.
Most times, the application will gather some relevant data, package it up in an Http response, and send it back to the browser. In Django, this process is handled by two files. The first is urls.py, and the second is views.py.
In this tutorial, we will be looking a little more closely at how Routing works in Django. Any web application needs to look at incoming Http requests and decide what to do with that request. Most times, the application will gather some relevant data, package it up in an Http response, and send it back to the browser.
It seems the custom error handlers
are the cause of it.
In Django 2.1
I had a custom handler for a 500 Error
error like this:
def error_500_view(request, exception):
return render(request,'500.html')
But in Django 2.2
it seems that the 500 Error
handler only takes 1 argument, so I changed to:
def error_500_view(request):
return render(request,'500.html')
And everything is working normal again.
So make sure your 404 Error
handler is something like:
def notfound(request, exception):
return render(request,'400.html')
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With