File: django_simple.py

package info (click to toggle)
python-pygraphviz 1.3.1-1~bpo8%2B1
  • links: PTS, VCS
  • area: main
  • in suites: jessie-backports
  • size: 664 kB
  • sloc: ansic: 4,970; python: 2,523; makefile: 152
file content (49 lines) | stat: -rw-r--r-- 1,384 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
Simple example for rendering a graph with the Django web framework.
See
http://www.djangoproject.com/
and
http://www.djangobook.com/en/beta/chapter11/

"""
#    Copyright (C) 2007 by 
#    Aric Hagberg <hagberg@lanl.gov>
#    Dan Schult <dschult@colgate.edu>
#    Manos Renieris, http://www.cs.brown.edu/~er/
#    Distributed with BSD license.     
#    All rights reserved, see LICENSE for details.

from __future__ import absolute_import
from __future__ import unicode_literals
from __future__ import print_function
from __future__ import division

__author__ = """Aric Hagberg (hagberg@lanl.gov)"""

try:
    from django.http import HttpResponse
except ImportError: # this won't run without Django, print message 
    print("Django not found.")

def pygraphviz_graph(request):
    import pygraphviz as P
    A=P.AGraph() # init empty graph
    # set some default node attributes
    A.node_attr['style']='filled'
    A.node_attr['shape']='circle'
    # Add edges (and nodes)
    A.add_edge(1,2)
    A.add_edge(2,3)
    A.add_edge(1,3)
    A.layout() # layout with default (neato)
    png=A.draw(format='png') # draw png
    return HttpResponse(png, mimetype='image/png')

if __name__ == '__main__':
    print("""This code works with the Django web framework
and should run as a django "view".
See djangoproject.com for info.

""")