Re: Is it possible to output a graph from Matplotlib into Django like this?

2011-04-13 Thread nai
Thanks for your help.

I went with 2 views, 1 for the image and 1 for the html.

On Apr 12, 2:06 pm, Sam Walters <mr.sam...@gmail.com> wrote:
> I mis-read this... basically you have one view and in the template you
> are rendering you put HTML:
>
> 
> 
>
> so that path will call your other views which return content as
> content_type='image/png' or whatever specific format you're using.
>
> what i was suggesting is you could have:
>
> 
> 
> 
>
> So in your urls.py file it would parameratize 'foo' and in your view
> method you could produce different responses based on the parameter.
> Eg: in an other view i have i can pass lat and long coords as params
> and it would put a dot on the map based on where that lat/long points
> to.
>
>
>
>
>
>
>
> On Tue, Apr 12, 2011 at 2:19 PM, nai <chng.nai...@gmail.com> wrote:
> > Actually, could you illustrate how you would go about using 2 views as
> > well? Thanks!
>
> > On Apr 11, 6:39 pm, Xavier Ordoquy <xordo...@linovia.com> wrote:
> >> Le 11 avr. 2011 à 12:21, nai a écrit :
>
> >> > This is the give example from Matplotlib for Django:
>
> >> > def simple(request):
> >> >    import random
>
> >> >    from matplotlib.backends.backend_agg import FigureCanvasAgg as
> >> > FigureCanvas
> >> >    from matplotlib.figure import Figure
> >> >    from matplotlib.dates import DateFormatter
>
> >> >    fig=Figure()
> >> >    ax=fig.add_subplot(111)
> >> >    x=[]
> >> >    y=[]
> >> >    now=datetime.datetime.now()
> >> >    delta=datetime.timedelta(days=1)
> >> >    for i in range(10):
> >> >        x.append(now)
> >> >        now+=delta
> >> >        y.append(random.randint(0, 1000))
> >> >    ax.plot_date(x, y, '-')
> >> >    ax.xaxis.set_major_formatter(DateFormatter('%Y-%m-%d'))
> >> >    fig.autofmt_xdate()
> >> >    canvas=FigureCanvas(fig)
> >> >    response=django.http.HttpResponse(content_type='image/png')
> >> >    canvas.print_png(response)
> >> >    return response
>
> >> > Is there anyway I can return the image like this `return
> >> > render_to_response('template.html', {'graph':  >> > matplotlib or some other graphing package>}`
>
> >> Hi,
>
> >> Is there any reasons why you couldn't have a view that would just render 
> >> the image and the other one that would have a img tag pointing to the 
> >> first view ?
> >> It is possible to embed an image in the web page, but I'm sure it goes 
> >> against the best practices.
>
> >> Regards,
> >> Xavier.
>
> > --
> > You received this message because you are subscribed to the Google Groups 
> > "Django users" group.
> > To post to this group, send email to django-users@googlegroups.com.
> > To unsubscribe from this group, send email to 
> > django-users+unsubscr...@googlegroups.com.
> > For more options, visit this group 
> > athttp://groups.google.com/group/django-users?hl=en.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: Is it possible to output a graph from Matplotlib into Django like this?

2011-04-11 Thread nai
You have to bear with me but where does background come from? So I can
use the save() method from the PIL library is that right?

And I can do something like this:

return render_to_response('template.html', {'graph':response})

Where graph is just a variable in my django template (and not )

Is that right?

On Apr 12, 12:03 pm, Sam Walters <mr.sam...@gmail.com> wrote:
> Use python imaging:http://www.pythonware.com/products/pil/
>
> You can return a response with an image of the graph.
>
> response = HttpResponse(status=200, mimetype="image/gif")
> background.save(response, "GIF")
> return response
>
> There is no 'best practice for this' Some people i know use flash.
> However dynamically generated images is good eg: no browser pluggins
>
> cheers
>
> sam_w
>
>
>
>
>
>
>
> On Tue, Apr 12, 2011 at 1:29 PM, nai <chng.nai...@gmail.com> wrote:
>
> > I will try to the 2 views method and see how I get on but in it would
> > be great if you could answer my questions too!
>
> > Why does it go against best practices?
>
> > How would one go about doing it anyway?
>
> > On Apr 11, 6:39 pm, Xavier Ordoquy <xordo...@linovia.com> wrote:
> >> Le 11 avr. 2011 à 12:21, nai a écrit :
>
> >> > This is the give example from Matplotlib for Django:
>
> >> > def simple(request):
> >> >    import random
>
> >> >    from matplotlib.backends.backend_agg import FigureCanvasAgg as
> >> > FigureCanvas
> >> >    from matplotlib.figure import Figure
> >> >    from matplotlib.dates import DateFormatter
>
> >> >    fig=Figure()
> >> >    ax=fig.add_subplot(111)
> >> >    x=[]
> >> >    y=[]
> >> >    now=datetime.datetime.now()
> >> >    delta=datetime.timedelta(days=1)
> >> >    for i in range(10):
> >> >        x.append(now)
> >> >        now+=delta
> >> >        y.append(random.randint(0, 1000))
> >> >    ax.plot_date(x, y, '-')
> >> >    ax.xaxis.set_major_formatter(DateFormatter('%Y-%m-%d'))
> >> >    fig.autofmt_xdate()
> >> >    canvas=FigureCanvas(fig)
> >> >    response=django.http.HttpResponse(content_type='image/png')
> >> >    canvas.print_png(response)
> >> >    return response
>
> >> > Is there anyway I can return the image like this `return
> >> > render_to_response('template.html', {'graph':  >> > matplotlib or some other graphing package>}`
>
> >> Hi,
>
> >> Is there any reasons why you couldn't have a view that would just render 
> >> the image and the other one that would have a img tag pointing to the 
> >> first view ?
> >> It is possible to embed an image in the web page, but I'm sure it goes 
> >> against the best practices.
>
> >> Regards,
> >> Xavier.
>
> > --
> > You received this message because you are subscribed to the Google Groups 
> > "Django users" group.
> > To post to this group, send email to django-users@googlegroups.com.
> > To unsubscribe from this group, send email to 
> > django-users+unsubscr...@googlegroups.com.
> > For more options, visit this group 
> > athttp://groups.google.com/group/django-users?hl=en.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: Is it possible to output a graph from Matplotlib into Django like this?

2011-04-11 Thread nai
Actually, could you illustrate how you would go about using 2 views as
well? Thanks!

On Apr 11, 6:39 pm, Xavier Ordoquy <xordo...@linovia.com> wrote:
> Le 11 avr. 2011 à 12:21, nai a écrit :
>
>
>
>
>
>
>
>
>
> > This is the give example from Matplotlib for Django:
>
> > def simple(request):
> >    import random
>
> >    from matplotlib.backends.backend_agg import FigureCanvasAgg as
> > FigureCanvas
> >    from matplotlib.figure import Figure
> >    from matplotlib.dates import DateFormatter
>
> >    fig=Figure()
> >    ax=fig.add_subplot(111)
> >    x=[]
> >    y=[]
> >    now=datetime.datetime.now()
> >    delta=datetime.timedelta(days=1)
> >    for i in range(10):
> >        x.append(now)
> >        now+=delta
> >        y.append(random.randint(0, 1000))
> >    ax.plot_date(x, y, '-')
> >    ax.xaxis.set_major_formatter(DateFormatter('%Y-%m-%d'))
> >    fig.autofmt_xdate()
> >    canvas=FigureCanvas(fig)
> >    response=django.http.HttpResponse(content_type='image/png')
> >    canvas.print_png(response)
> >    return response
>
> > Is there anyway I can return the image like this `return
> > render_to_response('template.html', {'graph':  > matplotlib or some other graphing package>}`
>
> Hi,
>
> Is there any reasons why you couldn't have a view that would just render the 
> image and the other one that would have a img tag pointing to the first view ?
> It is possible to embed an image in the web page, but I'm sure it goes 
> against the best practices.
>
> Regards,
> Xavier.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: Is it possible to output a graph from Matplotlib into Django like this?

2011-04-11 Thread nai
One reason why I don't quite like the idea is because I am writing a
reporting webapp and there are many different graphs that can
generated. Needing to write 2 views for 1 type of graph can get pretty
tedious!

On Apr 11, 6:39 pm, Xavier Ordoquy <xordo...@linovia.com> wrote:
> Le 11 avr. 2011 à 12:21, nai a écrit :
>
>
>
>
>
>
>
>
>
> > This is the give example from Matplotlib for Django:
>
> > def simple(request):
> >    import random
>
> >    from matplotlib.backends.backend_agg import FigureCanvasAgg as
> > FigureCanvas
> >    from matplotlib.figure import Figure
> >    from matplotlib.dates import DateFormatter
>
> >    fig=Figure()
> >    ax=fig.add_subplot(111)
> >    x=[]
> >    y=[]
> >    now=datetime.datetime.now()
> >    delta=datetime.timedelta(days=1)
> >    for i in range(10):
> >        x.append(now)
> >        now+=delta
> >        y.append(random.randint(0, 1000))
> >    ax.plot_date(x, y, '-')
> >    ax.xaxis.set_major_formatter(DateFormatter('%Y-%m-%d'))
> >    fig.autofmt_xdate()
> >    canvas=FigureCanvas(fig)
> >    response=django.http.HttpResponse(content_type='image/png')
> >    canvas.print_png(response)
> >    return response
>
> > Is there anyway I can return the image like this `return
> > render_to_response('template.html', {'graph':  > matplotlib or some other graphing package>}`
>
> Hi,
>
> Is there any reasons why you couldn't have a view that would just render the 
> image and the other one that would have a img tag pointing to the first view ?
> It is possible to embed an image in the web page, but I'm sure it goes 
> against the best practices.
>
> Regards,
> Xavier.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: Is it possible to output a graph from Matplotlib into Django like this?

2011-04-11 Thread nai

I will try to the 2 views method and see how I get on but in it would
be great if you could answer my questions too!

Why does it go against best practices?

How would one go about doing it anyway?


On Apr 11, 6:39 pm, Xavier Ordoquy <xordo...@linovia.com> wrote:
> Le 11 avr. 2011 à 12:21, nai a écrit :
>
>
>
>
>
>
>
>
>
> > This is the give example from Matplotlib for Django:
>
> > def simple(request):
> >    import random
>
> >    from matplotlib.backends.backend_agg import FigureCanvasAgg as
> > FigureCanvas
> >    from matplotlib.figure import Figure
> >    from matplotlib.dates import DateFormatter
>
> >    fig=Figure()
> >    ax=fig.add_subplot(111)
> >    x=[]
> >    y=[]
> >    now=datetime.datetime.now()
> >    delta=datetime.timedelta(days=1)
> >    for i in range(10):
> >        x.append(now)
> >        now+=delta
> >        y.append(random.randint(0, 1000))
> >    ax.plot_date(x, y, '-')
> >    ax.xaxis.set_major_formatter(DateFormatter('%Y-%m-%d'))
> >    fig.autofmt_xdate()
> >    canvas=FigureCanvas(fig)
> >    response=django.http.HttpResponse(content_type='image/png')
> >    canvas.print_png(response)
> >    return response
>
> > Is there anyway I can return the image like this `return
> > render_to_response('template.html', {'graph':  > matplotlib or some other graphing package>}`
>
> Hi,
>
> Is there any reasons why you couldn't have a view that would just render the 
> image and the other one that would have a img tag pointing to the first view ?
> It is possible to embed an image in the web page, but I'm sure it goes 
> against the best practices.
>
> Regards,
> Xavier.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Is it possible to output a graph from Matplotlib into Django like this?

2011-04-11 Thread nai
This is the give example from Matplotlib for Django:

def simple(request):
import random

from matplotlib.backends.backend_agg import FigureCanvasAgg as
FigureCanvas
from matplotlib.figure import Figure
from matplotlib.dates import DateFormatter

fig=Figure()
ax=fig.add_subplot(111)
x=[]
y=[]
now=datetime.datetime.now()
delta=datetime.timedelta(days=1)
for i in range(10):
x.append(now)
now+=delta
y.append(random.randint(0, 1000))
ax.plot_date(x, y, '-')
ax.xaxis.set_major_formatter(DateFormatter('%Y-%m-%d'))
fig.autofmt_xdate()
canvas=FigureCanvas(fig)
response=django.http.HttpResponse(content_type='image/png')
canvas.print_png(response)
return response

Is there anyway I can return the image like this `return
render_to_response('template.html', {'graph': }`

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Error: No module named mysql.base when trying to sync.db

2011-04-01 Thread nai
I posted the same question on stackoverflow here:
http://stackoverflow.com/questions/5509755/problem-with-django-syncdb-on-amazon-ec2

Reproduced

Hi all, I'm trying to deploy my project on my EC2 instance. When I run
python manage.py validate I get this error Error: No module named
mysql.base .

I have already installed MySQL-python using yum install MySQL-python.
I can import MySQLdb successfully from the Python interpreter.

I can't seem to figure out what's wrong?

I am using Django 1.3 and Python 2.6 and MySQLdb 1.2.3c1

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: Django app and Amazon AWS (beginner)

2011-03-09 Thread nai
According to djangoproject, deploying Django with apache and mod_wsgi
is the way to go. I keep seeing these terms over and over again but
I've had it explained to me over and over but I still don't get it. I
know this is getting a bit off topic but it would be great if someone
could take another stab and explain how apache and mod_wsgi fits in
with the deployment.

On Mar 10, 11:27 am, nai <chng.nai...@gmail.com> wrote:
> Ok, this is where I start running into the limitations of my
> knowledge. Does installing a webserver like Apache 'persist' the
> website then? Is that what I should be doing if I want to do things
> 'properly'?
>
> Also, when I run nohup, I get: nohup: ignoring input and appending
> output to `nohup.out'
>
> On Mar 10, 10:50 am, Huy Ton That <huyslo...@gmail.com> wrote:
>
>
>
>
>
>
>
> > Well, if you are just doing a development test, as it seems below foregoing
> > apache, you can do
>
> > sudo nohup python manage.py runserver 0.0.0.0:8000
>
> > It will keep on running after you close the terminal.
>
> > -H
>
> > On Wed, Mar 9, 2011 at 9:46 PM, nai <chng.nai...@gmail.com> wrote:
> > > Hi guys,
>
> > > I've been lurking on the forums and groups for a while now but I've
> > > recently ran into some problems I couldn't figure out whilst learning
> > > to code.
>
> > > Basically, I have a simple working webapp on my local machine. I've
> > > signed up for the free Amazon tier and have been messing around with
> > > it since. So my question is, once I run
>
> > > python manage.py runserver ec2-122-248-194-176.ap-
> > > southeast-1.compute.amazonaws.com:8000 &
>
> > > Everytime I close my terminal the site goes down even though I added
> > > the '&' to run it as a background task.
>
> > > Is there a better way of doing this? Are there any resources/books
> > > that shows you how to deploy on Amazon? Why isn't there a heroku for
> > > Django?
>
> > > Ok, that became a 3 part question :)
>
> > > Thanks.
>
> > > --
> > > You received this message because you are subscribed to the Google Groups
> > > "Django users" group.
> > > To post to this group, send email to django-users@googlegroups.com.
> > > To unsubscribe from this group, send email to
> > > django-users+unsubscr...@googlegroups.com.
> > > For more options, visit this group at
> > >http://groups.google.com/group/django-users?hl=en.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: Django app and Amazon AWS (beginner)

2011-03-09 Thread nai
Ok, this is where I start running into the limitations of my
knowledge. Does installing a webserver like Apache 'persist' the
website then? Is that what I should be doing if I want to do things
'properly'?

Also, when I run nohup, I get: nohup: ignoring input and appending
output to `nohup.out'

On Mar 10, 10:50 am, Huy Ton That <huyslo...@gmail.com> wrote:
> Well, if you are just doing a development test, as it seems below foregoing
> apache, you can do
>
> sudo nohup python manage.py runserver 0.0.0.0:8000
>
> It will keep on running after you close the terminal.
>
> -H
>
>
>
>
>
>
>
> On Wed, Mar 9, 2011 at 9:46 PM, nai <chng.nai...@gmail.com> wrote:
> > Hi guys,
>
> > I've been lurking on the forums and groups for a while now but I've
> > recently ran into some problems I couldn't figure out whilst learning
> > to code.
>
> > Basically, I have a simple working webapp on my local machine. I've
> > signed up for the free Amazon tier and have been messing around with
> > it since. So my question is, once I run
>
> > python manage.py runserver ec2-122-248-194-176.ap-
> > southeast-1.compute.amazonaws.com:8000 &
>
> > Everytime I close my terminal the site goes down even though I added
> > the '&' to run it as a background task.
>
> > Is there a better way of doing this? Are there any resources/books
> > that shows you how to deploy on Amazon? Why isn't there a heroku for
> > Django?
>
> > Ok, that became a 3 part question :)
>
> > Thanks.
>
> > --
> > You received this message because you are subscribed to the Google Groups
> > "Django users" group.
> > To post to this group, send email to django-users@googlegroups.com.
> > To unsubscribe from this group, send email to
> > django-users+unsubscr...@googlegroups.com.
> > For more options, visit this group at
> >http://groups.google.com/group/django-users?hl=en.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Django app and Amazon AWS (beginner)

2011-03-09 Thread nai
Hi guys,

I've been lurking on the forums and groups for a while now but I've
recently ran into some problems I couldn't figure out whilst learning
to code.

Basically, I have a simple working webapp on my local machine. I've
signed up for the free Amazon tier and have been messing around with
it since. So my question is, once I run

python manage.py runserver ec2-122-248-194-176.ap-
southeast-1.compute.amazonaws.com:8000 &

Everytime I close my terminal the site goes down even though I added
the '&' to run it as a background task.

Is there a better way of doing this? Are there any resources/books
that shows you how to deploy on Amazon? Why isn't there a heroku for
Django?

Ok, that became a 3 part question :)

Thanks.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Need help with Django tutorial

2011-01-16 Thread nai
I posted my question in Stackoverflow because its easier to see the
code blocks.

Basically, I am having problems trying to get my polls template from
the Django tutorial working properly.

Please have a look. Thanks.

The link is here: 
http://stackoverflow.com/questions/4705962/need-help-with-django-tutorial

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: django-admin.py not working?

2011-01-15 Thread nai
OMG THAT WORKED! Thank you so much but I don't understand why NONE of
the documentation mentioned anything about putting a python in front
of it. URGH!!

Thanks again!

On Jan 15, 6:19 pm, Acorn <shiniest.ac...@gmail.com> wrote:
> You will have to specially run the script with python.. so:
>
>    python FULLPATH\django-admin.py startproject webapp1
>
> I'm not sure why it behaves like this.
>
> On 15 January 2011 18:00, nai <chng.nai...@gmail.com> wrote:
>
>
>
>
>
>
>
> > I'm running Windows Vista and Im trying to create a project.
>
> > When I try to run FULLPATH\django-admin.py startproject webapp1, I get
> > back the help list. This happens no matter what subcommand I use. I
> > took a screen shot an posted a similar question on SO here
> >http://stackoverflow.com/questions/4696831/help-with-django-installation
>
> > Any help would be much appreciated.
>
> > Nai
>
> > --
> > You received this message because you are subscribed to the Google Groups 
> > "Django users" group.
> > To post to this group, send email to django-users@googlegroups.com.
> > To unsubscribe from this group, send email to 
> > django-users+unsubscr...@googlegroups.com.
> > For more options, visit this group 
> > athttp://groups.google.com/group/django-users?hl=en.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



django-admin.py not working?

2011-01-15 Thread nai
I'm running Windows Vista and Im trying to create a project.

When I try to run FULLPATH\django-admin.py startproject webapp1, I get
back the help list. This happens no matter what subcommand I use. I
took a screen shot an posted a similar question on SO here
http://stackoverflow.com/questions/4696831/help-with-django-installation

Any help would be much appreciated.

Nai

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.