python 散景到javascript html例证
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了python 散景到javascript html例证相关的知识,希望对你有一定的参考价值。
in views.py
def index(request):
if request.method == "GET":
return render(request, 'index.html')
elif request.method == "POST" :
domain = request.POST['domain'].split()
eqn = request.POST['equation']
domain = range( int(domain[0]), int(domain[1]) )
y = [ eval(eqn) for x in domain ]
title = 'y = ' + eqn
plot = figure(plot_width=400, plot_height=400, tools='hover,tap,wheel_zoom,pan,reset,help')
plot.multi_polygons(xs=[[[[1, 2, 2, 1, 1]]]],
ys=[[[[3, 3, 4, 4, 3]]]])
script, div = components(plot)
return render(request, 'index.html', {'script' : script , 'div' : div})
in index.hmtl
{% load staticfiles %}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>DAP Graph Plotter</title>
<link href="http://cdn.pydata.org/bokeh/release/bokeh-1.0.0.min.css" rel="stylesheet" type="text/css">
<link href="http://cdn.pydata.org/bokeh/release/bokeh-widgets-1.0.0.min.css" rel="stylesheet" type="text/css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/materialize/0.97.6/css/materialize.min.css">
<link rel="stylesheet" href="http://www.askprateek.com/style.css">
</head>
<body>
<nav>
<div class="nav-wrapper" style= "background:#FFC107">
<a href="/" class="brand-logo center">Graph Plotter</a>
<ul id="nav-mobile" class="right hide-on-med-and-down">
<li><a href="http://www.askprateek.com/">Contact</a></li>
<li><a href="https://github.com/askprateek/">Github</a></li>
<li><a href="https://twitter.com/AskPK123">Twitter</a></li>
<li><a href="https://github.com/askprateek/Django-Graph-Plotter">Fork</a></li>
</ul>
</div>
</nav>
<div class="container">
<div class="row">
<div class="col s12 m6">
{% csrf_token %}
<form method="post" action="{% url 'index' %}" > {% csrf_token %}
{% csrf_token %}
<div class="row">
<div class="col s12">
<label for="equation">Polynomial Equation - f(x)</label>
<input type ="text" id = "equation" name = "equation">
</div>
</div>
<div class="row">
<div class="col s12">
<label for="domain">Domain of Equation</label>
<input type = "text" id = "domain" name = "domain">
</div>
</div>
<div class="row">
<div class="col s12">
<button class="button">Draw Graph</button>
</div>
</div>
</form>
</div>
<div class="col s12 m6 center-align">
{{ div | safe }}
</div>
</div>
</div>
<script src="http://cdn.pydata.org/bokeh/release/bokeh-1.0.0.min.js"></script>
<script src="http://cdn.pydata.org/bokeh/release/bokeh-widgets-1.0.0.min.js"></script>
{{ script | safe }}
</body>
</html>
以上是关于python 散景到javascript html例证的主要内容,如果未能解决你的问题,请参考以下文章