Django类视图问题

大家新年快乐鸭:D
今天遇到一个django类视图的问题
view.py

class AddBook(View):
    def get(self, request, *args, **kwargs):
        return render(request, 'add_book.html')

    def post(self, request, *args, **kwargs):
        book_name = request.POST.get('name')
        book_author = request.POST.get('author')
        print('-' * 20)
        print('Book Name:{}    Author:{}'.format(book_name, book_author))
        return HttpResponse('Done.')

urls.py

urlpatterns = [
    ....
    url('biu/',cv.AddBook.as_view()),
]

url配置都没问题,为什么浏览器里面访问的时候会报错说找不到html文件呢?鼠标移动到add_book.html按住ctrl点击是可以跳转到对应的html文件里面的,所以这里应该也没有错啊
image.png
image.png
求助,谢谢啦

阅读 2.7k
1 个回答

弄明白了,原来是可以在settings里面加上这句:
\[os.path.join(BASE\_DIR,'templates')\]
image.png

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题