导入错误:无法从'django.conf.urls'中导入名称为'url'的模块 django-rest-auth。

7

错误: 从django.conf.urls导入url时出错 ImportError: 无法从'django.conf.urls'中导入名称'url'

- 版本信息 Django==4.0.1 django-rest-auth==0.9.5

Pl help me.Thank you in advance    

url.py

# Core Django imports
from django.contrib import admin
from django.urls import path, include
from django.urls import re_path,include
# from django.conf.urls import url,include
from django.conf import settings
# Rest framework imports
from rest_framework import permissions

# Simple JWT imports
from drf_yasg.views import get_schema_view
from drf_yasg import openapi

schema_view = get_schema_view(
    openapi.Info(
        title="Heathy Living Guide API",
        default_version='v1',
        description="Heathy Living Guide",
    ),
    public=True,
    permission_classes=(permissions.AllowAny,),
)

urlpatterns = (
    path('admin/', admin.site.urls),
    path('api/authentication/', include('apps.authentication.urls'),authentication'),
    path('api/users/', include('apps.users.urls'), name='users'),
    path('rest-auth/', include('rest_auth.urls')),
    # re_path(r'^rest-auth/', include('rest_auth.urls'))
)

urlpatterns += [
    path('api/swagger/', schema_view.with_ui('swagger', cache_timeout=0), name='schema-swagger-ui'),
    path('api/redoc/', schema_view.with_ui('redoc', cache_timeout=0), name='schema-redoc')
]
3个回答

10
根据 drf 文档

Django-rest-auth 是原始项目,但目前没有接收更新。

Dj-rest-auth 是项目的更新分支。

如果您仍想使用 django-rest-auth,则需要替换几个已弃用的 API 调用:
  • 对于 django.conf.urls,请使用

    from django.urls import re_path as url

  • 对于 ugettext,请使用

    from django.utils.translation import gettext_lazy as _

  • 对于 force_text,请使用

    from django.utils.encoding import force_str as force_text

来源

7

django-rest-auth不支持django 4.0。django-rest-auth看起来已经被放弃了,最后一次提交是3年前。


0

from django.conf.urls import url 替换为 from django.urls import re_path

urlpatterns = (
    re_path('admin/', admin.site.urls),
    re_path('api/authentication/', include('apps.authentication.urls'),authentication),
    re_path('api/users/', include('apps.users.urls'), name='users'),
    re_path('rest-auth/', include('rest_auth.urls')),
    # re_path(r'^rest-auth/', include('rest_auth.urls'))
)

请使用代码示例格式使您的答案更易读 - Thomas Blanquet

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接