基于Django的绘图显示图形,url视图问题

基于Django的绘图显示图形,url视图问题,django,plotly,Django,Plotly,我试图在plots.py上显示plotly创建的散点图,并在simulator.html上以html显示。 问题是,当我用以下代码运行服务器时,它显示了访问服务器时的基本错误,如下所示。 正如您在settings.py上看到的,我相信所有必要的设置都应该完成。 你们能找出这个错误的原因和解决方法吗 错误消息: TemplateDoesNotExist at /simulator/ simulator.html Request Method: GET Request URL: http://

我试图在plots.py上显示plotly创建的散点图,并在simulator.html上以html显示。 问题是,当我用以下代码运行服务器时,它显示了访问服务器时的基本错误,如下所示。 正如您在settings.py上看到的,我相信所有必要的设置都应该完成。 你们能找出这个错误的原因和解决方法吗

错误消息:

TemplateDoesNotExist at /simulator/
simulator.html
Request Method: GET
Request URL:    http://127.0.0.1:8000/simulator/
Django Version: 2.2.4
Exception Type: TemplateDoesNotExist
Exception Value:    
simulator.html
Exception Location: /Users/user/.pyenv/versions/3.7.3/lib/python3.7/site-packages/django/template/loader.py in select_template, line 47
Python Executable:  /Users/user/.pyenv/versions/3.7.3/bin/python3
Python Version: 3.7.3
Python Path:    
['/Users/user/Desktop/Django/price_simulator',
 '/Users/user/.pyenv/versions/3.7.3/lib/python37.zip',
 '/Users/user/.pyenv/versions/3.7.3/lib/python3.7',
 '/Users/user/.pyenv/versions/3.7.3/lib/python3.7/lib-dynload',
 '/Users/user/.pyenv/versions/3.7.3/lib/python3.7/site-packages',
 '/Users/user/.pyenv/versions/3.7.3/lib/python3.7/site-packages/IPython/extensions']
Server time:    Tue, 24 Sep 2019 11:14:59 +0000
INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'simulatorapp'
]
TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [BASE_DIR, 'templates'],
        'APP_DIRS': True,
        'OPTIONS': {
            'context_processors': [
                'django.template.context_processors.debug',
                'django.template.context_processors.request',
                'django.contrib.auth.context_processors.auth',
                'django.contrib.messages.context_processors.messages',
            ],
        },
    },
]
from django.shortcuts import render
from django.http.response import HttpResponse
from django.contrib.auth.models import User
from django.contrib.auth import authenticate, login
from django.shortcuts import redirect
import pandas as pd
from django.views.generic import TemplateView

from . import plots

class ScatterView(TemplateView):
    template_name='simulator.html'
    def get_context_data(self, **kwargs):
        context = super(ScatterView, self).get_context_data(**kwargs)
        context['scatter'] = plots.get_scatter()
        return context
from django.urls import path
from .views import signupfunc, loginfunc
from django.conf import settings
from django.conf.urls.static import static
from .views import ScatterView

urlpatterns = [
    path('signup/', signupfunc, name='signup'),
    path('login/', loginfunc, name='login'),
    path('simulator/', ScatterView.as_view(), name='simulator'),
]
simulator.html

{% extends 'base.html' %}

{% block customcss %}
{% endblock customcss %}

{% block header %}
<script src="https://cdn.plot.ly/plotly-latest.min.js"></script>
</div>
{% endblock header %}
<div class="card" style="width: 100%;margin-top: 15px">
        <div class="card-body">
            <h5 class="card-title">title</h5>
            {{ scatter|safe }}
        </div>
      </div>
url.py在应用程序文件夹中:

TemplateDoesNotExist at /simulator/
simulator.html
Request Method: GET
Request URL:    http://127.0.0.1:8000/simulator/
Django Version: 2.2.4
Exception Type: TemplateDoesNotExist
Exception Value:    
simulator.html
Exception Location: /Users/user/.pyenv/versions/3.7.3/lib/python3.7/site-packages/django/template/loader.py in select_template, line 47
Python Executable:  /Users/user/.pyenv/versions/3.7.3/bin/python3
Python Version: 3.7.3
Python Path:    
['/Users/user/Desktop/Django/price_simulator',
 '/Users/user/.pyenv/versions/3.7.3/lib/python37.zip',
 '/Users/user/.pyenv/versions/3.7.3/lib/python3.7',
 '/Users/user/.pyenv/versions/3.7.3/lib/python3.7/lib-dynload',
 '/Users/user/.pyenv/versions/3.7.3/lib/python3.7/site-packages',
 '/Users/user/.pyenv/versions/3.7.3/lib/python3.7/site-packages/IPython/extensions']
Server time:    Tue, 24 Sep 2019 11:14:59 +0000
INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'simulatorapp'
]
TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [BASE_DIR, 'templates'],
        'APP_DIRS': True,
        'OPTIONS': {
            'context_processors': [
                'django.template.context_processors.debug',
                'django.template.context_processors.request',
                'django.contrib.auth.context_processors.auth',
                'django.contrib.messages.context_processors.messages',
            ],
        },
    },
]
from django.shortcuts import render
from django.http.response import HttpResponse
from django.contrib.auth.models import User
from django.contrib.auth import authenticate, login
from django.shortcuts import redirect
import pandas as pd
from django.views.generic import TemplateView

from . import plots

class ScatterView(TemplateView):
    template_name='simulator.html'
    def get_context_data(self, **kwargs):
        context = super(ScatterView, self).get_context_data(**kwargs)
        context['scatter'] = plots.get_scatter()
        return context
from django.urls import path
from .views import signupfunc, loginfunc
from django.conf import settings
from django.conf.urls.static import static
from .views import ScatterView

urlpatterns = [
    path('signup/', signupfunc, name='signup'),
    path('login/', loginfunc, name='login'),
    path('simulator/', ScatterView.as_view(), name='simulator'),
]
视图。py:

TemplateDoesNotExist at /simulator/
simulator.html
Request Method: GET
Request URL:    http://127.0.0.1:8000/simulator/
Django Version: 2.2.4
Exception Type: TemplateDoesNotExist
Exception Value:    
simulator.html
Exception Location: /Users/user/.pyenv/versions/3.7.3/lib/python3.7/site-packages/django/template/loader.py in select_template, line 47
Python Executable:  /Users/user/.pyenv/versions/3.7.3/bin/python3
Python Version: 3.7.3
Python Path:    
['/Users/user/Desktop/Django/price_simulator',
 '/Users/user/.pyenv/versions/3.7.3/lib/python37.zip',
 '/Users/user/.pyenv/versions/3.7.3/lib/python3.7',
 '/Users/user/.pyenv/versions/3.7.3/lib/python3.7/lib-dynload',
 '/Users/user/.pyenv/versions/3.7.3/lib/python3.7/site-packages',
 '/Users/user/.pyenv/versions/3.7.3/lib/python3.7/site-packages/IPython/extensions']
Server time:    Tue, 24 Sep 2019 11:14:59 +0000
INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'simulatorapp'
]
TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [BASE_DIR, 'templates'],
        'APP_DIRS': True,
        'OPTIONS': {
            'context_processors': [
                'django.template.context_processors.debug',
                'django.template.context_processors.request',
                'django.contrib.auth.context_processors.auth',
                'django.contrib.messages.context_processors.messages',
            ],
        },
    },
]
from django.shortcuts import render
from django.http.response import HttpResponse
from django.contrib.auth.models import User
from django.contrib.auth import authenticate, login
from django.shortcuts import redirect
import pandas as pd
from django.views.generic import TemplateView

from . import plots

class ScatterView(TemplateView):
    template_name='simulator.html'
    def get_context_data(self, **kwargs):
        context = super(ScatterView, self).get_context_data(**kwargs)
        context['scatter'] = plots.get_scatter()
        return context
from django.urls import path
from .views import signupfunc, loginfunc
from django.conf import settings
from django.conf.urls.static import static
from .views import ScatterView

urlpatterns = [
    path('signup/', signupfunc, name='signup'),
    path('login/', loginfunc, name='login'),
    path('simulator/', ScatterView.as_view(), name='simulator'),
]

这与URL或视图没有任何关系。正如错误所说,Django没有找到您的模板;这是因为您没有正确指定目录。应该是:

    'DIRS': [os.path.join(BASE_DIR, 'templates')], 

谢谢,丹尼尔,我稍后再试。真的很感激!谢谢,先生,成功了!!非常感谢你的支持。