django pwa 错误 = 无法从 'django.conf.urls 导入名称 'url'

django pwa error = cannot import name 'url' from 'django.conf.urls

您好,我正在使用 Django 4.0.3,我尝试在我的项目中使用 django-pwa,但是当我运行服务器时,出现以下错误。

我按照本教程 geeksforgeeks:make-pwa-of-a-django-project 在我的项目中包含渐进式 Web 应用程序功能。

我认为 django.conf.urls 中的 url 已弃用。

我相信肯定存在一些解决方案...

请帮帮我。

错误

File "C:\Users\Republic Of Computer\Desktop\Master cours et TD\python\tberra3lipy\venv\lib\site-packages\pwa\urls.py", line 1, in <module>
    from django.conf.urls import url
ImportError: cannot import name 'url' from 'django.conf.urls' (C:\Users\Republic Of Computer\Desktop\Master cours et TD\python\tberra3lipy\venv\lib\site-packages\django\conf\urls\__init__.py)

urls.py

from django.contrib import admin
from django.conf.urls.static import static
from django.urls import path,include
from django.conf import settings

urlpatterns = [
    path('admin/', admin.site.urls),
    path('donation/',include('donation.urls',namespace='donation')),
    path('',include('pwa.urls')),
]+static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)

settings.py

from pathlib import Path
import os

INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'pwa',
    'accounts',
    'donation',
    
]

ROOT_URLCONF = 'src.urls' 
# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/3.2/howto/static-files/

STATIC_URL = '/static/'
#pwa
PWA_SERVICE_WORKER_PATH = os.path.join(BASE_DIR, 'static/js', 'serviceworker.js')
PWA_APP_NAME = 'tberra3li'
PWA_APP_DESCRIPTION = "app for blood donors"
PWA_APP_THEME_COLOR = '#000000'
PWA_APP_BACKGROUND_COLOR = '#ffffff'
PWA_APP_DISPLAY = 'standalone'
PWA_APP_SCOPE = '/'
PWA_APP_ORIENTATION = 'any'
PWA_APP_START_URL = '/'
PWA_APP_STATUS_BAR_COLOR = 'default'
PWA_APP_ICONS = [
    {
        'src': 'static/assets/img/icon-160x160.png',
        'sizes': '160x160'
    }
]
PWA_APP_ICONS_APPLE = [
    {
        'src': 'static/assets/img/icon-160x160.png',
        'sizes': '160x160'
    }
]
PWA_APP_SPLASH_SCREEN = [
    {
        'src': 'static/assets/img/icon.png',
        'media': '(device-width: 320px) and (device-height: 568px) and (-webkit-device-pixel-ratio: 2)'
    }
]
PWA_APP_DIR = 'ltr'
PWA_APP_LANG = 'en-US'

django.conf.urlsDjango 4 中被弃用,所以你不能在你的 Django 版本中使用 django-pwa,你需要使用 Django 3。否则,您可以 fork/edit django-pwa 替换 django.conf.urls.url(用于此 file) with django.urls.path, see this pull request.