Python 导入错误:无法导入名称';EntryView';从';条目。视图';
我正在导入我的观点:Python 导入错误:无法导入名称';EntryView';从';条目。视图';,python,django,Python,Django,我正在导入我的观点: from .views import HomeView, EntryView 我得到的错误是: ImportError: cannot import name 'EntryView' from 'entries.views' (. C:\Users\Kheri\dev\cfehome\blog\entries\views.py) */ 下面是我提供的文件: 视图。py: from django.shortcuts import render from django.v
from .views import HomeView, EntryView
我得到的错误是:
ImportError: cannot import name 'EntryView' from 'entries.views' (.
C:\Users\Kheri\dev\cfehome\blog\entries\views.py) */
下面是我提供的文件:
视图。py:
from django.shortcuts import render
from django.views.generic import ListView, DetailView
from .models import Entry
class HomeView(ListView):
model = Entry
template_name = 'entries/index.html'
context_object_name = "blog_entries"
class EntryView(DetailView):
model = Entry
template_name = 'entries/entry_detail.html'
url.py:
from django.urls import path
from .views import HomeView, EntryView
urlpatterns = [
path('', HomeView.as_view(), name = 'blog-home'),
path('entry/<int:pk>/', EntryView.as_view(), name = 'entry-detail')
]
from django.shortcuts import render
from django.views.generic import ListView, DetailView
from .models import Entry
class HomeView(ListView):
model = Entry
template_name = 'entries/index.html'
context_object_name = "blog_entries"
class EntryView(DetailView):
model = Entry
template_name = 'entries/entry_detail.html'
从django.url导入路径
从。视图导入HomeView、EntryView
URL模式=[
路径(“”,HomeView.as_view(),name='blog home'),
路径('entry/',EntryView.as_view(),name='entry detail')
]
尝试更正视图的缩进。py:
from django.urls import path
from .views import HomeView, EntryView
urlpatterns = [
path('', HomeView.as_view(), name = 'blog-home'),
path('entry/<int:pk>/', EntryView.as_view(), name = 'entry-detail')
]
from django.shortcuts import render
from django.views.generic import ListView, DetailView
from .models import Entry
class HomeView(ListView):
model = Entry
template_name = 'entries/index.html'
context_object_name = "blog_entries"
class EntryView(DetailView):
model = Entry
template_name = 'entries/entry_detail.html'
也有这个错误,看到我在url.py中有一个拼写错误 以我的方式 我有
路径(“”,AtricleListView.as_view(),name='article-list'),
而不是路径(“”,ArticleListView.as_view(),name='article-list'),
同样在导入ArticleListView
中,我不得不将其更改为ArticleListView
由此
from .views import (
AtricleListView
)
对此
from .views import (
ArticleListView
)
我的错误是这样的
ImportError:无法从“blog.views”导入名称“AtricleListView”
在这里你可以看到我试图导入“AtricleListView”,而不是真正的名称“AtricleListView”这是实际的缩进吗?如果是,则必须取消登录
EntryView
。它目前是HomeView
的一个内部类。