Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/366.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/django/24.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上载按钮旁边嵌入Bokeh绘图时出现ImportError_Python_Django_Bokeh - Fatal编程技术网

Python 尝试在Django上载按钮旁边嵌入Bokeh绘图时出现ImportError

Python 尝试在Django上载按钮旁边嵌入Bokeh绘图时出现ImportError,python,django,bokeh,Python,Django,Bokeh,我正在尝试将一个Bokeh情节嵌入到一个有上传按钮的Django站点中。我使用给出的示例作为起点,然后添加关于从中嵌入的说明。我使用了need-a-minimal-django-file-upload-example/for_-django_1.8,它可以正常工作。然后我修改了以下文件,但出现以下错误: ImportError:没有名为“myapp”的模块 您可以在此处看到我的目录结构以及修改/添加的三个文件: 如果无法加载图像,请单击此处: . └── myproject ├── d

我正在尝试将一个Bokeh情节嵌入到一个有上传按钮的Django站点中。我使用给出的示例作为起点,然后添加关于从中嵌入的说明。我使用了
need-a-minimal-django-file-upload-example/for_-django_1.8
,它可以正常工作。然后我修改了以下文件,但出现以下错误:

ImportError:没有名为“myapp”的模块

您可以在此处看到我的目录结构以及修改/添加的三个文件:

如果无法加载图像,请单击此处:

.
└── myproject
    ├── db.sqlite3
    ├── manage.py
    ├── media
    │   └── documents
    │       └── 2016
    │           └── 01
    │               ├── 12
    │               │   └── silico_0_truth_filtered_ptps.csv
    │               └── 15
    │                   └── silico_0_truth_filtered_ptps.csv
    └── myproject
        ├── __init__.py
        ├── myapp
        │   ├── admin.py
        │   ├── forms.py
        │   ├── __init__.py
        │   ├── migrations
        │   │   ├── 0001_initial.py
        │   │   ├── __init__.py
        │   │   └── __pycache__
        │   │       ├── 0001_initial.cpython-35.pyc
        │   │       └── __init__.cpython-35.pyc
        │   ├── models.py
        │   ├── __pycache__
        │   │   ├── admin.cpython-34.pyc
        │   │   ├── admin.cpython-35.pyc
        │   │   ├── forms.cpython-35.pyc
        │   │   ├── __init__.cpython-34.pyc
        │   │   ├── __init__.cpython-35.pyc
        │   │   ├── models.cpython-34.pyc
        │   │   ├── models.cpython-35.pyc
        │   │   ├── urls.cpython-35.pyc
        │   │   └── views.cpython-35.pyc
        │   ├── templates
        │   │   ├── list.html
        │   │   └── simple_chart.html
        │   ├── tests.py
        │   ├── urls.py
        │   └── views.py
        ├── __pycache__
        │   ├── __init__.cpython-34.pyc
        │   ├── __init__.cpython-35.pyc
        │   ├── settings.cpython-34.pyc
        │   ├── settings.cpython-35.pyc
        │   ├── urls.cpython-35.pyc
        │   └── wsgi.cpython-35.pyc
        ├── settings.py
        ├── urls.py
        └── wsgi.py
以下是
模板/simple\u chart.html

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Experiment with Bokeh</title>
    <script src="http://cdn.bokeh.org/bokeh/release/bokeh-0.8.1.min.js"></script>
    <link rel="stylesheet" href="http://cdn.bokeh.org/bokeh/release/bokeh-0.8.1.min.css">
</head>
<body>

    {{the_div|safe}}

    {{the_script|safe}}
</body>
</html>
这里是myapp/views.py:

# -*- coding: utf-8 -*-
from django.shortcuts import render_to_response
from django.template import RequestContext
from django.http import HttpResponseRedirect
from django.core.urlresolvers import reverse

from myproject.myapp.models import Document
from myproject.myapp.forms import DocumentForm

from django.shortcuts import render
from bokeh.plotting import figure
from bokeh.resources import CDN
from bokeh.embed import components

def list(request):
    # Handle file upload
    if request.method == 'POST':
        form = DocumentForm(request.POST, request.FILES)
        if form.is_valid():
            newdoc = Document(docfile=request.FILES['docfile'])
            newdoc.save()

            # Redirect to the document list after POST
            return HttpResponseRedirect(reverse('myproject.myapp.views.list'))
    else:
        form = DocumentForm()  # A empty, unbound form

    # Load documents for the list page
    documents = Document.objects.all()

    # Render list page with the documents and the form
    return render_to_response(
        'list.html',
        {'documents': documents, 'form': form},
        context_instance=RequestContext(request)
    )

def simple_chart(request):
    plot = figure()
    plot.circle([1,2], [3,4])

    script, div = components(plot, CDN)

    return render(request, "simple_chart.html", {"the_script":script, "the_div":div})

在花了几天时间仔细阅读Django教程之后,我看到了他们是如何在那里导入视图的,因此我将
myapp/url.py
更改为:

# -*- coding: utf-8 -*-
from django.conf.urls import patterns, url
from . import views

urlpatterns = patterns('myproject.myapp.views',
    url(r'^list/$', 'list', name='list'),
    url(r'^simple_chart/$', views.simple_chart, name="simple_chart"),
)

这消除了恐惧,尽管我无法解释原因

我很困惑。我的问题怎么不是一个现有的编程问题?它不是一个编程问题,这里没有任何问题要解决,你正在寻找一个人为你编写代码。我的问题真的与这个问题有很大不同吗?编辑:如果有帮助,则更新标题该问题已存在4年左右,并且自那时以来整个社区都发生了变化,如果这让您感觉更好,我也投票关闭了该问题。删除了我的评论,感谢您改进您的问题。
# -*- coding: utf-8 -*-
from django.conf.urls import patterns, url
from . import views

urlpatterns = patterns('myproject.myapp.views',
    url(r'^list/$', 'list', name='list'),
    url(r'^simple_chart/$', views.simple_chart, name="simple_chart"),
)