GVKun编程网logo

导入错误:无法从“rest_framework”导入名称“路由器”(无法导入exefile.reg 打开文件时出错)

4

在本文中,我们将给您介绍关于导入错误:无法从“rest_framework”导入名称“路由器”的详细内容,并且为您解答无法导入exefile.reg打开文件时出错的相关问题,此外,我们还将为您提供关于

在本文中,我们将给您介绍关于导入错误:无法从“rest_framework”导入名称“路由器”的详细内容,并且为您解答无法导入exefile.reg 打开文件时出错的相关问题,此外,我们还将为您提供关于Django 错误 - 导入错误:无法从“first_project”导入名称“first_app”、NullInjectorError:R3InjectorError(AppModule)[路由器->路由器->路由器]:NullInjectorError:没有路由器的提供程序、pandasgui 导入错误:无法从 'typing' (C:\Users\sefater\anaconda3\lib\typing.py) 导入名称 'Literal'、PyInstaller 导入错误:无法从“docx”导入名称“文档”的知识。

本文目录一览:

导入错误:无法从“rest_framework”导入名称“路由器”(无法导入exefile.reg 打开文件时出错)

导入错误:无法从“rest_framework”导入名称“路由器”(无法导入exefile.reg 打开文件时出错)

如何解决导入错误:无法从“rest_framework”导入名称“路由器”

我刚刚开始学习 Django REST 框架。我正在尝试完成官方文档中的快速入门。我收到此错误:

Exception in thread django-main-thread:
Traceback (most recent call last):
  File "F:\\Python\\lib\\threading.py",line 932,in _bootstrap_inner
    self.run()
  File "F:\\Python\\lib\\threading.py",line 870,in run
    self._target(*self._args,**self._kwargs)
  File "F:\\Python\\lib\\site-packages\\django\\utils\\autoreload.py",line 53,in
wrapper
    fn(*args,**kwargs)
  File "F:\\Python\\lib\\site-packages\\django\\core\\management\\commands\\runserver
.py",line 118,in inner_run
    self.check(display_num_errors=True)
  File "F:\\Python\\lib\\site-packages\\django\\core\\management\\base.py",line 392,in check
    all_issues = checks.run_checks(
  File "F:\\Python\\lib\\site-packages\\django\\core\\checks\\registry.py",line 70,in run_checks
    new_errors = check(app_configs=app_configs,databases=databases)
  File "F:\\Python\\lib\\site-packages\\django\\core\\checks\\urls.py",line 13,in
check_url_config
    return check_resolver(resolver)
  File "F:\\Python\\lib\\site-packages\\django\\core\\checks\\urls.py",line 23,in
check_resolver
    return check_method()
  File "F:\\Python\\lib\\site-packages\\django\\urls\\resolvers.py",line 408,in c
heck
    for pattern in self.url_patterns:
  File "F:\\Python\\lib\\site-packages\\django\\utils\\functional.py",line 48,in
__get__
    res = instance.__dict__[self.name] = self.func(instance)
  File "F:\\Python\\lib\\site-packages\\django\\urls\\resolvers.py",line 589,in u
rl_patterns
    patterns = getattr(self.URLconf_module,"urlpatterns",self.URLconf_modul
e)
  File "F:\\Python\\lib\\site-packages\\django\\utils\\functional.py",line 582,in u
rlconf_module
    return import_module(self.URLconf_name)
  File "F:\\Python\\lib\\importlib\\__init__.py",line 127,in import_module
    return _bootstrap._gcd_import(name[level:],package,level)
  File "<frozen importlib._bootstrap>",line 1014,in _gcd_import
  File "<frozen importlib._bootstrap>",line 991,in _find_and_load
  File "<frozen importlib._bootstrap>",line 975,in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>",line 671,in _load_unlocked
  File "<frozen importlib._bootstrap_external>",line 783,in exec_module
  File "<frozen importlib._bootstrap>",line 219,in _call_with_frames_remove
d
  File "F:\\Programming\\Python\\rest_framework\\rest_framework\\urls.py",line 18,in <module>
    from rest_framework import routers
ImportError: cannot import name ''routers'' from ''rest_framework'' (F:\\Programmi
ng\\Python\\rest_framework\\rest_framework\\__init__.py)

urls.py

from django.contrib import admin
from django.urls import path,include
from rest_framework import routers
from quickstart import views

router = routers.DefaultRouter()
router.register(r''users'',views.UserViewSet)
router.register(r''groups'',views.GroupViewSet)



urlpatterns = [
    path(''admin/'',admin.site.urls),path(''api-auth/'',include(''rest_framework.urls'',namespace=''rest_framework''))

]

views.py

from django.shortcuts import render
from django.contrib.auth.models import User,Group
from rest_framework import viewsets,permissions
from quickstart.serializers import UserSerializer,GroupSerializer


class UserViewSet(viewsets.ModelViewSet):
    """API endpoint that allows users to be viewed or edited."""
    queryset = User.objects.all().order_by(''-date_joined'')
    serializer_class = UserSerializer
    permission_classes = [permissions.IsAuthenticated]

class GroupViewSet(viewsets.ModelViewSet):
    """API endpoint that allows groups to be viewed or edited."""
    queryset = Group.objects.all()
    serializer_class = GroupSerializer
    permission_classes = [permissions.IsAuthenticated]

当然,我已经安装了 Rest Framework 和 Django。 如果有帮助,我正在使用 Python 3.7.9。 我已将其余框架添加到我安装的应用程序中: .

INSTALLED_APPS = [
        ''django.contrib.admin'',''rest_framework'',''django.contrib.auth'',''quickstart.apps.QuickstartConfig'',''django.contrib.contenttypes'',''django.contrib.sessions'',''django.contrib.messages'',''django.contrib.staticfiles'',]

我查看了有关路由器等的官方文档,他们以与我相同的方式导入路由器,但由于某些奇怪的原因,我的无法正常工作。可能是什么问题?

感谢您的帮助! :)

Django 错误 - 导入错误:无法从“first_project”导入名称“first_app”

Django 错误 - 导入错误:无法从“first_project”导入名称“first_app”

如何解决Django 错误 - 导入错误:无法从“first_project”导入名称“first_app”

我是 Django 的新手,刚开始使用新项目。

我在尝试传入应用程序 URL 时遇到了这个问题。

导入错误:无法从“first_project”导入名称“first_app” (E:\\Project\\Djangoproject\\first_project\\first_project_init_.py)

view.py inside the first_app

urls.py inside the first_app

urls.py inside the first_project

解决方法

尝试在 settings.py 中设置路径,如下所示:

# Build paths inside the project like this: os.path.join(BASE_DIR,...)
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
sys.path.insert(0,BASE_DIR)
sys.path.insert(0,os.path.join(BASE_DIR,''backend/apps''))
sys.path.insert(0,''backend/extra_apps''))

NullInjectorError:R3InjectorError(AppModule)[路由器->路由器->路由器]:NullInjectorError:没有路由器的提供程序

NullInjectorError:R3InjectorError(AppModule)[路由器->路由器->路由器]:NullInjectorError:没有路由器的提供程序

HttpClient 导入您的 .service.ts

import { HttpClient } from '@angular/common/http';

HttpClientModule导入app.module.ts并添加HttpClientModule导入数组

import { HttpClientModule } from '@angular/common/http';

 imports: [
    BrowserModule,AppRoutingModule,HttpClientModule
  ],
,

我在使用 @angular/router 的服务中遇到了同样的错误。我能够通过替换来修复它

@Injectable()

@Injectable({
  providedIn: 'root'
})

在服务类中。

pandasgui 导入错误:无法从 'typing' (C:\Users\sefater\anaconda3\lib\typing.py) 导入名称 'Literal'

pandasgui 导入错误:无法从 'typing' (C:\Users\sefater\anaconda3\lib\typing.py) 导入名称 'Literal'

如何解决pandasgui 导入错误:无法从 ''typing'' (C:\\Users\\sefater\\anaconda3\\lib\\typing.py) 导入名称 ''Literal''

我无法将 pandasgui 导入 jupyter notebook。以下是我收到的错误消息。 我将不胜感激。

导入错误:无法从 ''typing'' (C:\\Users\\sefater\\anaconda3\\lib\\typing.py) 导入名称 ''Literal''

PyInstaller 导入错误:无法从“docx”导入名称“文档”

PyInstaller 导入错误:无法从“docx”导入名称“文档”

如何解决PyInstaller 导入错误:无法从“docx”导入名称“文档”

我正在尝试使用 PyInstaller 将我的脚本转换为 .exe 文件...我的脚本正在使用 docx 模块,这会导致尝试创建 exe 时出现一些问题。我曾尝试将 docx.py 添加到与我的脚本相同的目录中,然后使用 PyInstaller,但它仍然无法正常工作:ImportError: cannot import name ''Document'' from ''docx''。 (导致此错误的行是 from docx import Document)。

解决方法

如果您在脚本所在的目录中有一个名为 docx 的模块,就会发生此错误。它不加载已安装的 docx 模块,而是加载优先的“本地”模块。

因此您需要撤消该步骤并尝试其他操作。

今天关于导入错误:无法从“rest_framework”导入名称“路由器”无法导入exefile.reg 打开文件时出错的介绍到此结束,谢谢您的阅读,有关Django 错误 - 导入错误:无法从“first_project”导入名称“first_app”、NullInjectorError:R3InjectorError(AppModule)[路由器->路由器->路由器]:NullInjectorError:没有路由器的提供程序、pandasgui 导入错误:无法从 'typing' (C:\Users\sefater\anaconda3\lib\typing.py) 导入名称 'Literal'、PyInstaller 导入错误:无法从“docx”导入名称“文档”等更多相关知识的信息可以在本站进行查询。

本文标签: