Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/277.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 模板不存在错误…在Django中运行manage.py时出错_Python_Django - Fatal编程技术网

Python 模板不存在错误…在Django中运行manage.py时出错

Python 模板不存在错误…在Django中运行manage.py时出错,python,django,Python,Django,这是url.py文件 (venv) sevenbits@sevenbits-H110M-H:~/chart-django/chart$ tree . ├── chart │   ├── __init__.py │   ├── __init__.pyc │   ├── settings.py │   ├── settings.pyc │   ├── urls.py │   ├── urls.pyc │   ├── views.py │   ├── views.pyc │   ├── wsgi.py

这是url.py文件

(venv) sevenbits@sevenbits-H110M-H:~/chart-django/chart$ tree
.
├── chart
│   ├── __init__.py
│   ├── __init__.pyc
│   ├── settings.py
│   ├── settings.pyc
│   ├── urls.py
│   ├── urls.pyc
│   ├── views.py
│   ├── views.pyc
│   ├── wsgi.py
│   └── wsgi.pyc
├── chartapp
│   ├── admin.py
│   ├── admin.pyc
│   ├── __init__.py
│   ├── __init__.pyc
│   ├── migrations
│   │   ├── __init__.py
│   │   └── __init__.pyc
│   ├── models.py
│   ├── models.pyc
│   ├── templates
│   │   └── chartapp
│   │       ├── base
│   │       │   ├── bootstrap_defaults.html
│   │       │   ├── css.html
│   │       │   └── js.html
│   │       ├── base.html
│   │       └── charts.html
│   ├── tests.py
│   ├── views.py
│   └── views.pyc
├── db.sqlite3
└── manage.py
这是my views.py文件

from django.conf.urls import patterns, include, url
from django.contrib import admin
from .views import HomeView, get_data

urlpatterns = [

    url(r'^admin/', include(admin.site.urls)),
    url(r'^$',HomeView.as_view(), name='home'),
    url(r'^api/data/$', get_data, name='api-data'),

]
位于charts.html的TemplateDoesNotExist
运行代码时会显示这种类型的错误。我已包含模板,但显示了错误。这可能是模板结构错误。如果有人能指出我犯错误的地方,这将非常有用。

您的
base.html
位于
chartapp
目录中,因此您的
extends
标记应为:

from django.http import JsonResponse
from django.shortcuts import render
from django.views.generic import View

class HomeView(View):
        def get(self, request, *args, **kwargs):
                return render(request, 'chartapp/charts.html', {})

def get_data(request, *args, **kwargs):
        data = {
                "sales": 100,
                "customers": 10,
        }
        return JsonResponse(data)

您的
base.html
位于
chartapp
目录中,因此您的
extends
标记应为:

from django.http import JsonResponse
from django.shortcuts import render
from django.views.generic import View

class HomeView(View):
        def get(self, request, *args, **kwargs):
                return render(request, 'chartapp/charts.html', {})

def get_data(request, *args, **kwargs):
        data = {
                "sales": 100,
                "customers": 10,
        }
        return JsonResponse(data)
试试这个

{% extends 'chartapp/base.html' %}
试试这个

{% extends 'chartapp/base.html' %}

确保已保存更改并重新启动服务器。完整的错误消息将为您提供有关未找到哪个模板以及Django为您的模板文件搜索了哪些目录的信息。请确保已保存更改并重新启动服务器。完整的错误消息将为您提供有关未找到哪个模板以及Django为您的模板文件搜索了哪些目录的信息。您可以在setting.py文件中添加模板设置吗?您可以在setting.py文件中添加模板设置吗?谢谢这个解决了错误需要包括chartapp。谢谢这个解决了错误需要包括chartapp。