Django无法导入模型

时间:2019-07-16 15:40:56

标签: python django

实际上我正试图从 posts 文件夹中导入模型,并且出现以下错误。

AttributeError: module 'posts' has no attribute 'views'

这是urls.py

from django.contrib import admin
from django.urls import path
from . import views
from django.conf.urls import include
import accounts
import posts

urlpatterns = [
    path('admin/', admin.site.urls),
    path('',views.home, name = 'home'),
    path('login/',include('accounts.urls')),
    path('signup/',accounts.views.signup, name='signup' ),
    path('logout/',accounts.views.logout, name='logout'),
    path('posts/',posts.views.myposts)
]

我的urls.py位于posts文件夹外部 enter image description here

这是我的帖子文件夹

enter image description here

这是我的posts.views

from django.shortcuts import render, HttpResponse

# Create your views here.

def myposts(request):
    return HttpResponse('all_post.html')

0 个答案:

没有答案