Forums

ImportError: No module named 'django.urls' after "classic" system image end-of-life migration

I've rebuilded my virtualenv using this https://help.pythonanywhere.com/pages/RebuildingVirtualenvs due "classic" system image end-of-life and i'm getting this error:

2022-12-14 18:09:54,218: ImportError: No module named 'django.urls' 2022-12-14 18:09:54,218: File "/home/louvordaceu/gsdb/myenv/lib/python3.5/site-packages/django/core/handlers/wsgi.py", line 170, in call 2022-12-14 18:09:54,219:
self.load_middleware() 2022-12-14 18:09:54,219: 2022-12-14 18:09:54,219: File "/home/louvordaceu/gsdb/myenv/lib/python3.5/site-packages/django/core/handlers/base.py", line 50, in load_middleware 2022-12-14 18:09:54,219: mw_class = import_string(middleware_path) 2022-12-14 18:09:54,219: 2022-12-14 18:09:54,219: File "/home/louvordaceu/gsdb/myenv/lib/python3.5/site-packages/django/utils/module_loading.py", line 26, in import_string 2022-12-14 18:09:54,219: module = import_module(module_path) 2022-12-14 18:09:54,220: 2022-12-14 18:09:54,220: File "/home/louvordaceu/gsdb/myenv/lib/python3.5/site-packages/whitenoise/middleware.py", line 9, in <module> 2022-12-14 18:09:54,220: from django.urls import get_script_prefix

I'm using python 3.5 and django 1.8.19

urls.py:

"""gsdb URL Configuration

The `urlpatterns` list routes URLs to views. For more information please see:
    https://docs.djangoproject.com/en/1.8/topics/http/urls/
Examples:
Function views
    1. Add an import:  from my_app import views
    2. Add a URL to urlpatterns:  url(r'^$', views.home, name='home')
Class-based views
    1. Add an import:  from other_app.views import Home
    2. Add a URL to urlpatterns:  url(r'^$', Home.as_view(), name='home')
Including another URLconf
    1. Add an import:  from blog import urls as blog_urls
    2. Add a URL to urlpatterns:  url(r'^blog/', include(blog_urls))
"""
from django.conf.urls import include, url
#from django.urls import include, path
from django.contrib import admin
from gospelsongsdb import views

urlpatterns = [
    url(r'^$', views.index),
    url(r'^admin/', include(admin.site.urls)),
    url(r'^log/', views.Log.as_view(), name='log'),
    url(r'^mais_tocadas/', views.MostPlayed.as_view(), name='log'),
]

The location of urls changed in Django 2.0, so you should use django.conf.urls like in the code above, see: https://docs.djangoproject.com/en/1.8/ref/urls/.

hi louvordaceu, may i ask why you use django 1.8.19? are there any particular reasons for you not using newer version of django?

Because I use django-admin-bootstrapped.

Python 3.5 and Django 1.8 are both after the end of life for many years already. We have old system images supporting python 3.5 on PythonAnywhere but it will be gone rather sooner than later. See https://help.pythonanywhere.com/pages/ChangingSystemImage#available-python-versions-for-system-images