File: skip_django_simple.py

package info (click to toggle)
python-pygraphviz 1.14-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 732 kB
  • sloc: ansic: 5,100; python: 2,669; makefile: 57
file content (47 lines) | stat: -rw-r--r-- 1,213 bytes parent folder | download | duplicates (2)
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
"""
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.

__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.

"""
    )