Я пытаюсь запустить проект, скачанный по ссылке django-bokeh-example . Когда я запустил сервер и загрузил веб-страницу, я увидел только пустую страницу при проверке, я узнал, что при загрузке javascript и css произошла какая-то ошибка. После поиска в Google я узнал, что мне нужно установить какие-то статические параметры. Но я не совсем понял, как и где установить эти параметры ниже, это мой код. Я попытался добавить из импорта bokeh.resources INLINE , но это не помогло. Может кто-нибудь, пожалуйста, пролить свет на это
views.py
from django.shortcuts import render, render_to_response
from django.http import HttpResponse
from bokeh.plotting import figure, output_file, show
from bokeh.embed import components
from bokeh.resources import INLINE
def debug(x, name):
print('\n' * 5)
print('{} = {}'.format(name, x))
print('type({}) = {}'.format(name, type(x)))
print('\n' * 5)
def home(request):
return render_to_response('home_links.html')
def plot(request):
x = [1, 2, 3, 4, 5]
y = [6, 7, 2, 4, 5]
# output to static HTML file
output_file("lines.html")
# create a new plot with a title and axis labels
p = figure(title="simple line example", x_axis_label='x', y_axis_label='y')
# add a line renderer with legend and line thickness
p.line(x, y, legend="Temp.", line_width=2)
# Store components
script, div = components(p)
# Feed them to the Django template.
return render(request, 'bokeh_graph.html',
{'script': script, 'div': div})
def vbar(request):
plot = figure(plot_width=800, plot_height=500, x_axis_type = 'datetime')
from random import randint
x = [i for i in range(15)]
y = [randint(1, 100) for i in range(len(x))]
plot.vbar(x=x, width=0.5, bottom=0, top=y, color="#CAB2D6")
plot.xaxis.axis_label = 'Tempo'
plot.yaxis.axis_label = 'Ocorrencias'
plot.title.text_font = "times"
plot.title.text_font_style = "italic"
plot.title.text = 'A good title'
plot.title.align = 'center'
plot.title.text_font_size = '20pt'
script, div = components(plot)
# Feed them to the Django template.
return render(request, 'bokeh_graph.html',
{'script': script, 'div': div})
бок-graph.html
{% extends 'base.html' %}
{% block title %} Bokeh child! {% endblock %}
{% block head %}
<link rel="stylesheet" href="https://cdn.pydata.org/bokeh/release/bokeh-0.12.16.min.css" type="text/css" />
<script type="text/javascript" src="https://cdn.pydata.org/bokeh/release/bokeh-0.12.16.min.js"></script>
<script type="text/javascript">
Bokeh.set_log_level("info");
</script>
{% endblock %}
{% block main %}
{{ div | safe }}
{{ script | safe }}
{% endblock %}
urls.py
from django.urls import include, path
from . import views
urlpatterns = [
path('', views.home, name='home'),
path('plot', views.plot, name='plot'),
path('vbar', views.vbar, name='bar'),
]